Page 1 of 1

Randomly select rows from MySQL Database

Posted: Mon Jul 04, 2005 8:39 am
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

Posted: Mon Jul 04, 2005 9:21 am
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?

Understood

Posted: Mon Jul 04, 2005 9:28 am
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.