php - randomize mysql output as easily as possible -


i have mysql statement:

$mysql=mysql_query("select id,name table1 order id limit 10"); 

from i'm doing

while($row = mysql_fetch_array($mysql)){     echo $row['name'].'<br>'; } 

now i'm trying shuffle rows got out of mysql without using order rand() thats causing slowdown.

whats correct syntax program in rows come out shuffled?

if don't need them to

"come out shuffled"

...as in "out of database," can shuffle after retrieve of records.

since can fetch rows associative array, can shuffle result. give random order of rows returned.

in case:

$mysql = mysql_query("select id,name table1 order id limit 10");  $results = array(); //this might unnecessary  while($row = mysql_fetch_array($mysql)) {     array_push($results, $row); }  shuffle($results); foreach( $results $row ) {     echo $row['name'] . "<br />"; } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -