php - saving a random order.

Far

tsniffer
Staff member
Developer
May 19, 2003
20,184
30
2,788
540
Hey guys, im hoping someone on here can solve my problem. ive been thinking for days and just cant find a way to do it.

iv got a list of questions from a table, listed in a while() loop, split up in to pages of 4. i need them to randomize the first time, but when i go back and forward through the pages, stay in that order.

heres abit of my script

PHP:
$getexamquestion="SELECT * from examquestion where examid='$id' ORDER BY ExamID DESC LIMIT $from, $blog_postnumber";
				$getexamquestion2=mysql_query($getexamquestion) or die("Could not get exam questions");
				
				$questionnum = ($page - 1) * $blog_postnumber;

				while($getexamquestion3=mysql_fetch_array($getexamquestion2))
				{

atm its ordered by ExamID, i need a way to order it randomly like Rand() but always keep that order.

any help?
 

Kaori

LOMCN MiR3 Queen!
VIP
Jun 3, 2004
3,584
38
285
Canada
you will need to randomize it first and put the order in another array.
so the idea is...
read everything to an $array first (you may need to make sure it's an 1 dimension array)
then do a shuffle($array);
then the $array should be random