Randomly select rows from MySQL Database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
karenandbrian
Forum Newbie
Posts: 2
Joined: Mon Jul 04, 2005 8:23 am

Randomly select rows from MySQL Database

Post by karenandbrian »

I have a database with 10 rows. I would like to display each row one at a time in random order. How can I select rows from a database in random order without repeting a row? Basically I would like to reorder the database for each user so that the user will see all of the rows in a different order. I understand the rand() function but I need to limit the query so that each question is only asked once.

I am new to PHP and MySQL so I am just looking to be pointed in the right direction. Maybe just suggest a function that I could use and I will do the research.

Thanks
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Yo,

you can use the MYSQL RAND() to randomise the results. but then you have the problem of asking a repeated question right?

well mysql & php will need to know what questions were asked!

you will need to create another table that records the questions already asked and then have msqyl randomise the results based on questions not found in the table that records the already asked questions

understand?
karenandbrian
Forum Newbie
Posts: 2
Joined: Mon Jul 04, 2005 8:23 am

Understood

Post by karenandbrian »

I will give it a try, thanks for your advice. This is exactly what I was looking for just a suggestion on how to approach the situation. Thanks again.
Post Reply