Jump to content

Rows echoing problem


raphael1

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.