Jump to content


Photo

Displaying random records from database


  • Please log in to reply
2 replies to this topic

#1 DarkHorizon

DarkHorizon
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationScotland

Posted 03 October 2005 - 08:24 AM

If i have a mysql database with 10 items in it. How do i display any 3 at random?

Every time the front page loads on my website i need 3 random products to appear.

I know how to display and sort databases, its the statement to retrieve a random items that is confusing me..

cheers guys..

#2 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 03 October 2005 - 10:05 AM

SELECT * FROM `table` ORDER BY RAND() LIMIT 3
Cook

#3 DarkHorizon

DarkHorizon
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationScotland

Posted 04 October 2005 - 09:08 AM

SELECT * FROM `table` ORDER BY RAND() LIMIT 3

View Post


cheers mate, i'll give that a try




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users