Jump to content

Archived

This topic is now archived and is closed to further replies.

aviatorisu

Question about loops

Recommended Posts

Hi all, looking for a little help here.

I'm designing a website to review restaurants, shows, etc. around town, and I've learned quite a bit so far during this time. Each review is going to have a section allowing members to post their own comments. I've started into this script, and have a question about how to display the info. I only want to display 2 or 3 random comments for that particular place being reviewed. What would be the best way to go about picking out the comments from the database and then displaying them? Is there a way to limit the results? What if only 1 comment has been left, will it display the same comment to the max number of results?

Thanks in advance.

~Z~

Share this post


Link to post
Share on other sites
from the mysql manual

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
ORDER BY RAND() combined with LIMIT is useful for selecting a random sample of a set of rows:

mysql> SELECT * FROM table1, table2 WHERE a=b AND c<d
-> ORDER BY RAND() LIMIT 1000;
[/quote]

Share this post


Link to post
Share on other sites

×

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.