Jump to content


Photo

Question about loops


  • Please log in to reply
1 reply to this topic

#1 aviatorisu

aviatorisu
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 22 May 2006 - 02:24 AM

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~

#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 22 May 2006 - 02:48 AM

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]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users