Hi Guys, I am making a social networking site where I want to have a user's pals shown in a PHP generated table. I want to show pal thumbnails and other information below these thumbnails so that if you click on a thumbnail, it takes you to that user's profile.
My code:
//query username
$user_id = $_SESSION['UserSession'];
$user_id = mysql_real_escape_string($user_id);
mysql_select_db($database_connections, $connections);
$query_user_info = "SELECT username FROM users WHERE user_id='$user_id'";
$user_info = mysql_query($query_user_info, $connections) or die(mysql_error());
$row_user_info = mysql_fetch_assoc($user_info);
//code for displaying all your pals
$query_pal_array = "SELECT pal_array FROM users WHERE user_id='$user_id'";
$pal_array_result = mysql_query($query_pal_array, $connections) or die(mysql_error());
$row_pal_array = mysql_fetch_assoc($pal_array_result);
$pal_array = $row_pal_array['pal_array'];
$palList = "";
if($pal_array !="")
{
$palArray = explode(",",$pal_array);
$palCount = count($palArray);
}
else
{
$palCount = "0";
}
//get pal info
$query_pal_info = "SELECT users.user_id, user_first_name, user_last_name, username, picture_thumb_url, avatar FROM users LEFT JOIN picture ON
users.user_id = picture.user_id
AND picture.avatar=1 WHERE users.user_id IN ($pal_array)";
$pal_info = mysql_query($query_pal_info , $connections) or die(mysql_error());
$totalRows_pal_info = mysql_num_rows($pal_info );
//echo table with pal information
echo "\n<table>";
$j = 5;
while ($row_pal_info = mysql_fetch_assoc($pal_info))
{
$palArray = explode(",",$pal_array);
//$palArray = array_slice($palArray,0,15);
$k = 0;//how many times we loop over
foreach($palArray as $key =>$array_value)
{
$k++;
//increment by one
$palList = "$array_value";
echo $palList;
}
if($j==5) echo "\n\t<tr>";
$thumbnail_user = $row_pal_info['picture_thumb_url'] != '' ? $row_pal_info['picture_thumb_url'] : '../Style/Images/default_avatar.png';
echo "<td width='100' height='100' align='center' valign='middle'><a href = 'user_view.php?user_id2=$palList'>
<img src='/NNL/User_Images/$thumbnail_user' border='0'/></a></td>\n";
$j--;
if($j==0) {
echo "\n\t</tr>\n\t<tr>";
$j = 5;
}
}
if($j!=5) echo "\n\t\t<td colspan=\"$j\"></td>\n\t</tr>";
echo "\n</table>";
?>
I have user_id values stored in an array $pal_array. These are pal user_id numbers. When the thumbnails show, they all link to the last user_id in the array. How should I solve this? Im just learning PHP.
When I echo $palList above, I get 9492 9492 ie, user_id 94 and 92. The 2 thumbnails both link to user 92's profile.