Selecting random rows from database initially while preserving that order later I am building a quiz app, in which the student can login and can select the option of give exam. I want to show multiple choice questions to students randomly. 

I stored all the questions in one table. For example, I stored 20 questions for a chemistry exam. Now I want to show 10 random questions to students. I don't want to select questions randomly every time when user refresh the page. Currently I am doing:

SELECT * from table-name order by rand() limit 5;


The problem is this query selects random rows every time the user refreshes the page. This is my code:

&lt;?php
$query="SELECT * from question_bank order by rand() limit 10";
$result= mysqli_query($connection,$query);
confirm_query($result);

?&gt;

&lt;form action="result.php" name="form1" method="post" id="quiz"&gt;
&lt;?php
while ($read_all_data = mysqli_fetch_assoc($result))
{ 
    $_SESSION['id']=1;

$id=$read_all_data['question_id'];
$a=$read_all_data['a'];
$b=$read_all_data['b'];
$c=$read_all_data['c'];
$d=$read_all_data['d'];
 echo $read_all_data['question']."&lt;/br&gt;";
 echo "A:&lt;input type ='radio' value ='a'  name='$id' &gt;".$read_all_data['a']."&lt;/br&gt;";
 echo "B:&lt;input type ='radio' value ='b'  name='$id' &gt;".$read_all_data['b']."&lt;/br&gt;";
 echo "C:&lt;input type ='radio' value ='c'  name='$id' &gt;".$read_all_data['c']."&lt;/br&gt;";
 echo "D:&lt;input type ='radio' value ='d'  name='$id' &gt;".$read_all_data['d']."&lt;/br&gt;";

}
You'll want to hold an actual random number for each user then you can call

rand($usersrandomnumber) 


to generate your static random generator start point

the $usersrandomnumber acts as a starting seed

see the mysql documentation here:
https://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand

it will involve you storing the user's seed in a table somewhere, or cookie /local/server storage but will get you what you're after