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
https://forums.phpfreaks.com/topic/271551-limit-the-number-of-search-results/
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.

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.