Jump to content

[SOLVED] display all comments not just one


dachshund

Recommended Posts

Hi,

 

I have this code, but it only displays the single most recent comment. I want it to display the whole array of comments in order of id.

 

Can anyone help?

 

Here's my code:

 

 


<?php

if($_SESSION['uid']){

	$sessionname=$_SESSION['uid'];
	$articleid=$rows['id'];
	$commentsql="SELECT * FROM comments WHERE articleid ='$id' ORDER BY id DESC LIMIT 10";
	$commentresult=mysql_query($commentsql) or die (mysql_error());
	$commentrows=mysql_fetch_array($commentresult);
	$query="SELECT * FROM users WHERE id = '$sessionname'";
	$userresult=mysql_query($query);
	$userrow = mysql_fetch_assoc($userresult);

	echo "<ul>";
	echo "<li>Leave a comment</li>";
	echo "<li>";
	echo "<form name=\"comment\" method=\"post\" action=\"";
	include $_SERVER['DOCUMENT_ROOT'];
	echo "/test/commentposted.php?id=";
	echo $articleid;
	echo "\">";
	echo "<textarea name=\"comment\" rows=\"5\"></textarea>";
	echo "</li>";
	echo "<li>";
	echo "<input type=\"submit\" name=\"submitcomment\" value=\"Comment\">";
	echo "</form>";
	echo "</li>";
	echo "<li>";
	echo $userrow['username'];
	echo "</li>";
	echo "<li>";
	echo $commentrows['comment'];
	echo "</li>";
	echo "</ul>";

}else	{
	echo "<ul><li>You must be logged in to post a comment.</li>";
	echo "<li>";
	echo $userrow['username'];
	echo "</li>";
	echo "<li>";
	echo $commentrows['comment'];
	echo "</li>";
	echo "</ul>";
}

mysql_close();
}
?>

 

like this?

 

        <?php

	$commentsql="SELECT * FROM comments WHERE articleid ='$id' ORDER BY id DESC LIMIT 10";
	$commentresult=mysql_query($commentsql) or die (mysql_error());
	$commentrows=mysql_fetch_array($commentresult);
	$query="SELECT * FROM users WHERE id = '$sessionname'";
	$userresult=mysql_query($query);
	$userrow = mysql_fetch_assoc($userresult);
	while($commentrows=mysql_fetch_array($commentresult)){

	?>
        
        <li>
	<? echo $userrow['username']; ?>
	</li>
	<li>
	<? echo $commentrows['comment']; ?>
	</li>
	</ul>
        
        <?php
}
mysql_close()

?>

 

 

that still only returns a single result.

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.