raphael1 Posted November 23, 2010 Share Posted November 23, 2010 For some reason my php script only echo's out one data, I can't seem to find the problem. <? $show = mysql_query("SELECT * FROM video_comments WHERE pageid='$vidid'"); $numrows = mysql_num_rows($show); if ($numrows > 0){ while($row = mysql_fetch_array($show)){ $userid = $row["userid"]; $username = $row["username"]; $comment = $row["comment"]; $date = $row["date"]; $date = strftime("%b %d, %Y", strtotime($date)); } echo" <table style='background-color:#FFF; border:#999 1px solid; border-top:none;' cellpadding='5' width='100%'> <tr> <td width='90%' valign='top' style='line-height:1.5em;'><span class='greenColor textsize10'>$date<a href='profile.php?id=$userid'> $username </a> said:</span><br /> $comment</td> </tr> </tr></table> "; } else echo"<center><font face='arial' size='2'><p>This video has no comments.</font></center>"; ?> Link to comment https://forums.phpfreaks.com/topic/219572-rows-echoing-problem/ Share on other sites More sharing options...
New Coder Posted November 23, 2010 Share Posted November 23, 2010 You need to put the echo detail within the while loop otherwise I'm assuming it's only echoing the last record found or rarther than build the table every time you could just add to it like: <? $show = mysql_query("SELECT * FROM video_comments WHERE pageid='$vidid'"); $numrows = mysql_num_rows($show); if ($numrows > 0) { $list = "<table style='background-color:#FFF; border:#999 1px solid; border-top:none;' cellpadding='5' width='100%'>"; while($row = mysql_fetch_array($show)) { $userid = $row["userid"]; $username = $row["username"]; $comment = $row["comment"]; $date = $row["date"]; $date = strftime("%b %d, %Y", strtotime($date)); $list .= "<tr>"; $list .= "<td width='90%' valign='top' style='line-height:1.5em;'><span class='greenColor textsize10'>$date<a href='profile.php?id=$userid'> $username </a> said:</span><br /> $comment</td>"; $list .= "</tr>"; } $list .= "<table>"; echo ( $list ); } else { echo"<center><font face='arial' size='2'><p>This video has no comments.</font></center>"; } ?> Code not tested but should give you an idea Link to comment https://forums.phpfreaks.com/topic/219572-rows-echoing-problem/#findComment-1138403 Share on other sites More sharing options...
MrXHellboy Posted November 23, 2010 Share Posted November 23, 2010 Confirm that. The last result will be stored! Link to comment https://forums.phpfreaks.com/topic/219572-rows-echoing-problem/#findComment-1138404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.