So I have a while loop inside a while loop. It is a list of photos and under each photo is the comment section. However, each comment is listing as many times as I have photos. Example, photo 1 of 4 left one comment and it is repeated 4 times (same comment). I just need each comment to be listed once. What can I do with this code? Keep in mind this is only the section that I’m having an issue with. I tried to highlight the while statement in red that is repeating. Thanks!
[php]
else if( $cid && empty( $pid ) )
{
$number_of_thumbs_in_row = 3;
$result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
$nr = mysql_num_rows( $result );
if( empty( $nr ) )
{
$result_final = "\t<tr><td><p>You have no personal photos uploaded by PixiPics at this time.<br/>
If you feel this is not correct please <a href=\"inquiry.php\">contact us</a>.</p></td></tr>\n";
}
else
{
while($row = mysql_fetch_array( $result ))
{
$result2 = mysql_query( "SELECT f.id, f.detail, f.question_filename, g.photo_filename, g.photo_category FROM forum_question as f, gallery_photos as g WHERE question_filename = '".$row[2]."' AND photo_category = '".addslashes($cid)."' ORDER BY id DESC");
$data = '';
while ($rows=mysql_fetch_array($result2)){
$data .= '<tr><td><a href="view_topic.php?id='.$rows[id].'">'.$rows[detail]."</a></td></tr>";
}
$result_array[] = "<a href='http://184.173.230.159/~pixipics/members.php?cid=$cid&pid=\"$row[0]\"'><img src='".$images_dir."/tb_".$row[2]."' border='4' alt='".$row[1]."' /></a><br /><p>Comments:</p>
<div class='toggle'>
<table>
<form id='form1' name='form1' method='post' action='add_topic.php'>
<tr>
<td><strong>Add New Comment:</strong></td>
</tr>
<tr>
<td><textarea name='detail' cols='25' rows='3' id='detail'></textarea></td>
</tr>
<tr>
<td><input type='hidden' id='question_name' name='question_name' value='".$info['name']."'/></td>
</tr>
<tr>
<td><input type='hidden' id='question_filename' name='question_filename' value='".$row[2]."'/></td>
</tr>
<tr>
<td><input type='submit' name='Submit' value='Submit' /> <input type='reset' name='Submit2' value='Reset' /></td>
</tr>
</form>
<tr>
<td><strong>Select a Comment:</strong></td>
</tr>
".$data."
</table>
</div>
";
}
mysql_free_result( $result );
$result_final = "<tr>\n";
foreach($result_array as $thumbnail_link)
{
if($counter == $number_of_thumbs_in_row)
{
$counter = 1;
$result_final .= "\n</tr>\n<tr>\n";
}
else
$counter++;
$result_final .= "\t<td>".$thumbnail_link."</td>\n";
}
if($counter)
{
if($number_of_photos_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n";
$result_final .= "</tr>";
}
}
}
[/php]