Forum Moderators: coopster

Message Too Old, No Replies

Randomize Displaying Rows

         

inveni0

4:24 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



Is there a way to randomize which table row is displayed in a query?

For instance, if I have a table with 10 rows, and each row has just one column with random numbers or letters in it, can the page load one row and then, when refreshed, load another?

jatar_k

4:43 pm on Jan 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



with a small set of results you could select them all into an array and then display a random row from the array. With a larger set it may be slow.

vevs

5:09 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



if you are talking for a mysql table, then you can use
SELECT * FROM TABLE ORDER by rand() LIMIT 0,1
which will return a random row from the table

inveni0

3:02 am on Jan 21, 2006 (gmt 0)

10+ Year Member



Works great, thanks!