...

View Full Version : Function not returning expected value



schalk1807
10-28-2012, 05:21 PM
Can anyone please tell me why this function is returning the user_id as contained in the $friends variable, instead of the first_name and last_name?



public function getFriendsById($friends) {
$sql="SELECT first_name, last_name FROM users WHERE user_id =". $friends;
$results = mysql_query($sql)or die("Selection Query Failed !!!");
$friendsNames = array();
while ($row = mysql_fetch_array($results)){
$friendsNames[] = $row['first_name, last_name'];
}
return $friendsNames;
}

}

tangoforce
10-28-2012, 07:03 PM
Can anyone please tell me why this function is returning the user_id as contained in the $friends variable, instead of the first_name and last_name?



$friendsNames[] = $row['first_name, last_name'];


You can't do that. The best you can do is this:



$friendsNames[] = "$row[first_name], $row[last_name]";

//OR
$friendsNames[] = $row['first_name'] .', ' .$Row['last_name'];

schalk1807
10-28-2012, 07:07 PM
Thanx for your reply.

changed it using your code.

no change

tangoforce
10-29-2012, 12:18 AM
In that case you need to run the SQL statement in phpmyadmin in the SQL page and see what happens.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum