[wd_asp elements=’search’ ratio=’100%’ id=1]

Random – Get Records Mysql Randomly 6 at a time

18th January 2015

MySql

mysql codehaven category


$result = mysql_query("SELECT * FROM quiz WHERE id != $qnum ORDER BY RAND() limit 5");
while($row = mysql_fetch_array($result))
{
$answer2 = $row['answer2'];

}
var_dump($answer2);

Creates this
{ [0]=> string(6) " Bern^" [1]=> string(8) " Prague^" [2]=> string(8) " Berlin^" [3]=> string(10) " Sarajevo^" [4]=> string(12) " San Marino^" }

The results will be different each time it is run.