If you require the user to go through all the questions once in random order, you will need to track an individual βplaylistβ for each user. Preferred use of sessions:
session_start(); if (!$_SESSION['ids']) { $_SESSION['ids'] = $db->getAllQuestionIdsFromTheDatabase(); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // Leaving this up to you. shuffle($_SESSION['ids']); // $_SESSION['ids'] should now look like array(42, 12, 75, ...); } $question = $db->getQuestionById(array_shift($_SESSION['ids'])); ...
You can randomize either in the database using ORDER BY RAND() , or in PHP using shuffle , or that's fine.
source share