Page 1 of 1

SOLVED - Need Help With Random Query Display

Posted: Wed Nov 07, 2007 6:21 pm
by grozanc
Hello,

I'm new to PHP/MYSQL and don't really know the proper way to search for a solution to my question.

When a user visits a page on my site, I want that page to randomly display table entires that have the number 1 in a specific column that I have setup in MySQL. Basically I have 100 stories in a database, I want 10 of them to be randomly displayed when someone visits the page. Let me know if I'm being to vague, like I mentioned I don't know how to even ask the question. oops:


Any link to a tutorial or the proper terminology so I can do a better search would be appreciated.

Thanks,
Gary

Posted: Wed Nov 07, 2007 6:28 pm
by feyd
You'll want to look at the ORDER BY clause and the RAND() function provided by MySQL.

Posted: Wed Nov 07, 2007 6:42 pm
by grozanc
Thanks for the reply. Will your suggestions give me the ability to display only 1 of the entries?

Posted: Wed Nov 07, 2007 6:56 pm
by John Cartwright

Code: Select all

.. ORDER BY RAND() LIMIT 1

SOLVED - Need Help With Random Query Display

Posted: Wed Nov 07, 2007 7:27 pm
by grozanc
Thanks everyone! I was able to figure out how to accomplish what I needed from you suggestions.