Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm hoping someone can help me. I have to make it so that a coded table is written when there are less than two comments posted. If there are no comments, then nothing should be posted. My problem is that i can't figure out how to fill out loop statement to just skip over the code if no comments exist. I've tried every variation of if else, do while and can't find an elegant way. Any suggestions?Code: Select all
$query2 = "SELECT * FROM comments where recipe_id = '$rnum' ORDER BY 'date' ASC";
$result2 = mysql_query($query2, $link) or die('Could not add retrieve comments : ' . mysql_error($link));
$total_comments = mysql_num_rows($result2);
for ($x=0; $x <= $total_comments; $x++){
$row2 = mysql_fetch_array($result2);
$rcomment[$x] = $row2['comment'];
$ruser_id[$x] = $row2['user_id'];
$cdate[$x] = $row2['date'];
$crating[$x] = $row2['rating'];
}
for($x=0;$x<2;$x++){
echo"<table>";
echo"<tr> ";
echo"<td colspan=\"3\"><em><a href=\"index.php?view=allcomments&rnum=$rnum\"><strong>View All Comments:</a></em> Total Comments:</strong> $total_comments</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=\"111\" > Member:</td>";
echo"<td width=\"119\" > $ruser_id[$x]</td>";
echo"<td width=\"133\" align=\"right\"> Date: </td>";
echo"<td width=\"133\" > $cdate[$x]</td>";
echo"</tr>";
echo"<tr>";
echo"<td valign=\"top\"> Comment:</td>";
echo"<td colspan=\"3\">$rcomment[$x]</td>";
echo"</tr>";
echo"<tr>";
echo"<td colspan=\"4\"> <hr></td></tr>";
echo"</table>";
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]