Absolute beginner in PHP, so please be patient.
I am trying to use the $friends variable from function getFriends() in the getFriendsById () function, but even when I tried declaring $friends as global, it doesn’t work.
I recieve the following 2 error messages:
Notice: Undefined property: User::$friends
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given.
Any advice please.
[php]
function getFriends(){
$sql=“select friend_id from user_friends where user_id =” .$this->user_id;
$results = mysql_query($sql);
$friends = array();
$this->friends = $friends;
while ($row = mysql_fetch_array($results)){
$friends[] = $row[‘friend_id’];
}
return $friends;
}
/* This is the function which must use the friends id's to extract the names
and surnames of the friends from the "users" table in the database and return values*/
public function getFriendsById() {
$sql="SELECT first_name, last_name FROM user WHERE user_id =". $this->friends;
$results = mysql_query($sql);
$friendsNames = array();
while ($row = mysql_fetch_array($results)){
$friendsNames[] = $row["first_name, last_name"];
}
return $friendsNames;
}
}
[/php]