Jump to content

Limit The Number Of Search Results


elmas156

Recommended Posts

Hello, I'm creating a "comments" section for my website, and I want to display a few of my most recent comments posted by users. I know how I would display ALL of the comments posted, but not sure how I would display only a few... say 4 or 5 comments. Anyone have any suggestions or ideas?

 

Here's my current code:

 

<?php

 $resultcomm = mysql_query("SELECT `name`,`comment` FROM comments ORDER BY `index` DESC") or die (mysql_error());

 while ($rowcomm = mysql_fetch_row($resultcomm)) {

	 $name = $rowcomm[0];
	 $comment = $rowcomm[1];

	 echo "<p class='p14'>$comment<br />";
	 echo "<div class='p15'>- $name</div></p>";
	 echo "<hr width='200' />";

 }

?>

 

Thanks for any help!

Link to comment
Share on other sites

Just as a guess, to limit the search to 5 results, would I use the LIIMIT clause in this manner? I'm not near my computer with my code right now, so I can't test it for myself...

 

$resultcomm = mysql_query("SELECT `name`,`comment` FROM comments ORDER BY `index` DESC LIMIT 5") or die (mysql_error());

 

Thanks again for your help.

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.