how do i search from php file ?
- by Tum Bin
Dear Friends, im totally new in php. Just learning. I got 2 Assingment with php and html. Assignment 01:
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:
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.
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.
for this I have to use the function “post/get/request”
Plz plz plzzzzzzzzzz help me! Here im posting my codes;
<?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", "Ishita"),
"Nandini" => array("Bonna", "Shakib", "Kamal", "Minhaj", "Ishita"),
"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;
?>