SOLVED - Need Help With Random Query Display

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grozanc
Forum Newbie
Posts: 14
Joined: Tue Oct 23, 2007 6:50 pm

SOLVED - Need Help With Random Query Display

Post 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
Last edited by grozanc on Wed Nov 07, 2007 8:06 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll want to look at the ORDER BY clause and the RAND() function provided by MySQL.
grozanc
Forum Newbie
Posts: 14
Joined: Tue Oct 23, 2007 6:50 pm

Post by grozanc »

Thanks for the reply. Will your suggestions give me the ability to display only 1 of the entries?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

.. ORDER BY RAND() LIMIT 1
grozanc
Forum Newbie
Posts: 14
Joined: Tue Oct 23, 2007 6:50 pm

SOLVED - Need Help With Random Query Display

Post by grozanc »

Thanks everyone! I was able to figure out how to accomplish what I needed from you suggestions.
Post Reply