For several time I use to select random rows as:
$get_question = $user_home->runQuery('SELECT * FROM questions WHERE Level = :Level ORDER BY RAND()');
An expert told me that,
RAND() is a recipe for killing MySQL server !!
So, with the help of this answer I tried:
$get_question = $user_home->runQuery('SELECT * FROM questions AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(Sr) FROM questions)) AS Sr) AS r2 WHERE r1.Sr >= r2.Sr AND Level = :Level ORDER BY r1.Sr ASC LIMIT 1');
And this is how I display the result:
echo $fetch_question['Question'] . "(" . $fetch_question['Id'] . ")";
And the display is:
question(id)
But, sometimes it displays only:
()
Why so? What is the mistake that I did?