Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with showing correct user_id link from array values in while loop
    primarykey
    data
    text
    <p>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. </p> <p>My code:</p> <pre><code>&lt;?php //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 avatars $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 $pal_array; echo "\n&lt;table&gt;"; $j = 5; while ($row_pal_info = mysql_fetch_assoc($pal_info)) { if($j==5) echo "\n\t&lt;tr&gt;"; $thumbnail_user = $row_pal_info['picture_thumb_url'] != '' ? $row_pal_info['picture_thumb_url'] : '../Style/Images/default_avatar.png'; echo "&lt;td width='100' height='100' align='center' valign='middle'&gt;&lt;a href = 'user_view.php?user_id2=$pal_array'&gt; &lt;img src='/NNL/User_Images/$thumbnail_user' border='0'/&gt;&lt;/a&gt;&lt;/td&gt;\n"; $j--; if($j==0) { echo "\n\t&lt;/tr&gt;\n\t&lt;tr&gt;"; $j = 5; } } if($j!=5) echo "\n\t\t&lt;td colspan=\"$j\"&gt;&lt;/td&gt;\n\t&lt;/tr&gt;"; echo "\n&lt;/table&gt;"; ?&gt; &lt;table width="500" border="0"&gt; &lt;tr&gt; &lt;td height="20"&gt;&lt;div class="heading_text_18"&gt;&lt;?php echo $row_user_info ['username']; ?&gt;'s&amp;nbsp;pals &lt;?php echo $palCount ?&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="interactionLinksDiv" align="right" style="border:none;"&gt;&lt;a href="#" onclick="return false" onmousedown="javascript: toggleInteractContainers('pal_requests');"&gt;Pal Requests&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="5"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>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. What am I doing wrong. Im just learning PHP.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload