Here's a sketch of the random-selection bit.
I'm assuming you can uniquely identify all the possible answers in the pool (and which of them is correct) for each question. I'm assuming this because I need it for what follows:
Get the unique identifer (uid) for the correct answer to the question and put it in an array:
$poss_ans_id = array($correct_ans_id);
Now, we need the number of answers in the pool that can go with our question; you need some way of knowing which those are that you can have something to go in the WHERE clause of
"SELECT COUNT(*) AS num_answers FROM yourtable WHERE conditions"
With $num_answers under our belt, we start picking items out at random. The fiddly bit here is that we want each one to be unique.
Before any use of the RNG we need to seed it. At least once per script.
srand((double)microtime()*1000000);
How many possible answers do you want? Four plus the correct one?
while(count($poss_ans_id)<5)
{ $candidate_offset=rand(0,$num_answers-1);
The query is
SELECT ans_id FROM yourtable WHERE conditions OFFSET $candidate_offset LIMIT 1
and we get a single $ans_id. We stick it in our array if it's not there already
if(!in_array($ans_id,$poss_ans_id))
{ array_push($poss_ans_id,$ans_id);
}
} //And complete the loop
We shuffle the array to mix the uid for the correct answer in with the others:
shuffle($poss_ans_id)
And we have an array; five uids representing five different answers in the database.
To get the questions to go with the ids, something like:
"SELECT * FROM yourtable WHERE uid IN (".join(',',$poss_ans_id.")"
would then be in order.