显示随机问题

I am designing a test where in I want to display questions randomly. I have 50 questions in the database. For this I have written the following code :

$singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question' ORDER BY Rand()"); 

        while($row = mysql_fetch_array($singleSQL)){
            $id = $row['id'];
            $thisQuestion = $row['question'];
            $type = $row['type'];
            $question_id = $row['question_id'];
            $q = '<h2>'.$thisQuestion.'</h2>';
            $sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question' ORDER BY rand()");
            while($row2 = mysql_fetch_array($sql2)){
                $answer = $row2['answer'];
                $correct = $row2['correct'];
                $answers .= '<label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer.'</label> 
                <input type="hidden" id="qid" value="'.$id.'" name="qid"><br /><br />
                ';

            }
            $output = ''.$q.','.$answers.',<span id="btnSpan"><button onclick="post_answer()">Submit</button></span>';
            echo $output;
           }

This rand() function in the first line is not working for questions but the same function is working for answers(options of MCQs appears randomly). Also when I do changes in sql query in the first line I get the error :

Warning:

mysql_fetch_array() expects parameter 1 to be resource
boolean given in C:\xampp\htdocs\questions.php on line 36
undefined.

I dont know what's wrong!! Pls help me out..!!

The WHERE id = '$question' clause in the first query is making it return just a single question that matches that ID, not all the questions. You need to remove that.

$singleSQL = mysql_query("SELECT * FROM questions ORDER BY Rand()"); 

And inside the loop, you're using the wrong variable in the second query. It should be:

$sql2 = mysql_query("SELECT * FROM answers WHERE question_id='$question_id' ORDER BY rand()");

Extra information on ORDER BY Rand():

ORDER BY Rand() works fine when you are working with small database, say, 1000 rows. But when it comes to large database it cause performance problem. Read this article for more information and alternate solution.

As of your question, Barmar point out exactly what's wrong with the code.

1. $singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question' ORDER BY Rand()");

Here you are randomizing for only one row which make no sense.

2. mysql_query("SELECT * FROM answers WHERE question_id='$question' ORDER BY    rand()");

It should be WHERE id='$question_id' instead of WHERE id='$question'