Jump to content

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.

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.