Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
plz help me with multidimention function and get/post/request
Old 01-16-2011, 12:15 PM plz help me with multidimention function and get/post/request
Junior Talker

Posts: 2
Name: Rana
Trades: 0
Dear Friends, im totally new in php. Just learning. I got 2 Assingment with php and html. Assignment 01:

1. I have to mansion some pplz name and all of them some friends name. and I have to print common friend if there have common friend. Bt there have a prob that I got also msg which dnt have any common friend like “Rana has 0 friends in common with Roni.” I want to stop this and how can i?

Assignment 02: I made a html form to search a person from that php file. Like:

1. when I will search for Rana php form will b open and and print : Rana have 4 friends and he has a common friend with Nandini and Mamun.
2. when I will search for Tanmoy the page will be open and print: Tonmoy is Rana’s friend who have 4 friend and common friends with Nandini and Mamun.
3. for this I have to use the function “post/get/request”

Plz plz plzzzzzzzzzz help me! Here im posting my codes;

PHP Code:
<?php
       
# Function: finfCommon

    
function findCommon($current$arr) {
        
$cUser $arr[$current];
        unset(
$arr[$current]);
        foreach (
$arr As $user => $friends) {
            
$common = array();
            
$total = array();
            foreach (
$friends As $friend) {
                if (
in_array($friend$cUser)) {
                    
$common[] = $friend;
                }
            }
            
$total count($common);
            
$add = ($total != 1) ? 's' '';
            
$final[] = "<i>{$current} has {$total} friend{$add} in common with {$user}.</i>";
        }
        return 
implode('<br />'$final);
    }

# Array of users and friends
    
$Friends = array(
        
"Rana" => array("Pothik""Zaman""Tanmoy""I****a"),
        
"Nandini" => array("Bonna""Shakib""Kamal""Minhaj""I****a"),
        
"Roni" => array("Akbar""Anwar""Khakan""Pavel"),
        
"Liton" => array("Mahadi""Pavel"),
        
"Mamun" => array("Meheli""Tarek""Zaman")
    );

# Creating the output value
    
$output "<ul>";
    foreach (
$Friends As $user => $friends) {
        
$total count($friends);
        
$common findCommon($user$Friends);
         
$output .= "<li><u>{$user} has {$total}  friends.</u><br /><strong>Friends:</strong>";
        if (
is_array($friends) && !empty($friends[0])) {
            
$output .= "<ul>";
            foreach (
$friends As $friend) {
                
$output .= "<li>{$friend}</li>";
            }
            
$output .= "</ul>";
        }
        
$output .= "{$common}<br /><br /></li>";
    }
    
$output .= "</ul>";

# Printing the output value
    
print $output;
        
?>

Last edited by chrishirst; 01-16-2011 at 12:21 PM..
tum_bin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-17-2011, 02:02 AM Re: plz help me with multidimention function and get/post/request
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
This is an exercise in use of functions and arrays. You're on the right lines with the function to produce an array of friends for a given name but you're trying to do too much in the function -- just return the array (no html, no added strings) and let the calling code decide what to do next. Take the problems one by one. Do the function and test it for the first requirement. Then expand the calling code to do the second requirement. Finally, create the form and add it to the code you've written. POST and GET aren't functions by the way, they're the method you put on the form.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-17-2011, 02:45 AM Re: plz help me with multidimention function and get/post/request
Junior Talker

Posts: 2
Name: Rana
Trades: 0
Quote:
Originally Posted by PaulW View Post
This is an exercise in use of functions and arrays. You're on the right lines with the function to produce an array of friends for a given name but you're trying to do too much in the function -- just return the array (no html, no added strings) and let the calling code decide what to do next. Take the problems one by one. Do the function and test it for the first requirement. Then expand the calling code to do the second requirement. Finally, create the form and add it to the code you've written. POST and GET aren't functions by the way, they're the method you put on the form.

Thanx Sir for Ur reply. U Said that i tried too much in the function. then how can i out of their? how can i make it more easier? will U help me by coding? if possible plz. actually i did lotz of way, bt cant calling codes for search. will U help me out? i will eagerly wait for Ur reply Sir.
tum_bin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to plz help me with multidimention function and get/post/request
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62233 seconds with 12 queries