Page 1 of 1

Get mysql on random

Posted: Fri Apr 13, 2007 4:35 am
by hmsg
Hello ppl

I need to access the values of a mysql query in random ways, this means, when i do a mysql query for example i have 5 rows, but i only want to access the row 2 and the row 4, how can i access the rows that i want ? I need something like this: $row=mysql_fetch_array($query, $number_register)



With the best regards

Hugo Gomes

Posted: Fri Apr 13, 2007 5:50 am
by Oren
If you need rows 2 and 4, how's that random? :?

Posted: Fri Apr 13, 2007 6:20 am
by timvw
http://www.php.net/mysql_data_seek allows you to navigate in the resultset...

Posted: Fri Apr 13, 2007 9:54 am
by pickle
You can also ORDER BY RAND() LIMIT 2 in your query.

Posted: Fri Apr 13, 2007 10:43 am
by RobertGonzalez
Go with pickle's idea. That is the best way to get a set number of random rows returned.