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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.