php - randomly choose one data from blocks of query -


i have 100000 records in table. need make query reads 10 records , after 10 more records continuously until end of table. each of 10 rows groups, need pick 1 random row. possible accomplish using mysql query? need idea this. can me?

i have tried php loop doesn't work.

<?php include_once ("connection.php");  $data = mysql_query("select * trying"); $result = array();   while ($data2 = mysql_fetch_array($data)) {     array_push($result, array('no'=> $data2['no'],                       'source'=> $data2['source'],                  'destination'=> $data2['destination'])); }  $e=0;    ($a = 0; $a <= 49;) {      ($i = 0; $i <= 9; $i++,$a++) {         $rand = array();         $rand[$i] = $result[$a];       }     echo json_encode($rand[1]);  }  ?> 

insted of this:

for ($a = 0; $a <= 49;) {      ($i = 0; $i <= 9; $i++,$a++) {         $rand = array();         $rand[$i] = $result[$a];       }     echo json_encode($rand[1]);  } 

you can use this:

$rand = array(); $step = 10;  ($min = 0; $min <= 49; $min = $min + $step) {        $max = $min + $step;     $rand[] = $result[rand($min,$max)]; } echo json_encode($rand); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -