I am trying to access the $Frined_Id outside the while loop. But it is only returning the last accessed element. Is there any method so that i can store the value of Friend Id inside the array and then can use them in program whenever i want.
$query="SELECT * FROM `user_friend` WHERE `User_Id`='$id'";
if($query_run=mysql_query($query))
{
$mysql_num_rows=mysql_num_rows($query_run);
$i=$mysql_num_rows;
while($row=mysql_fetch_array($query_run))
{
$Friend_Id=$row['Friend_Id'];
$Name=$row['Friend_Name'];
$Name_array=array("$Name");
echo "<a href=\"view_profile.php?id=$Friend_Id\"/>".$Name."</a>".'<br>';
}
echo $Friend_Id;
}
The reason it only shows the last one is because it gets changed each time in the loop and the last thing it was set to is what it is. A fix for being able to access all of them is make $Friend_Id an array as such:
Then after your loop, you can access them by index
You can make it even more useful by making an associative array containing the name and id like:
Just a few ideas…