0

テーブル2のid、question_id、answer、correctのテーブル1に、id、subject、exam、qution、qution_idを含む2つのテーブルがあります。ここでは、使用しているデータベースからランダムな質問を取得するのに問題があります

$singleSQL = mysql_query("SELECT * FROM questions WHERE id='$question'  LIMIT 1");
    while($row = mysql_fetch_array($singleSQL)){
        $id = $row['id'];
        $thisQuestion = $row['question'];
        $type = $row['type'];
        $subject =$row['subject'];
        $exam =$row['exam'];
        $explan =$row['explan'];
        $question_id = $row['question_id'];
        $s ='<strong>'.$subject.'</strong>';
        $e ='<small>'.$exam.'</small>';
        $q = '<h2>'.$thisQuestion.'</h2>';
        $ex ='<p class="exp">'.$explan.'</p>';
        $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 .= '<table class="table table-hover table-bordered"> <tr>
            <td><label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'">'.$answer.'</label></td>
            </tr></table>
            <input type="hidden" id="qid" value="'.$id.'" name="qid"><br />
            ';

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

回答の送信をクリックすると、次の質問がランダムに表示されるはずです

 index.php?question=

ページが読み込まれるたびに、データベースからランダムな質問を取得する必要があります。plz help iam in need of this thanx before before.

4

2 に答える 2

1
$randomparameter = mysql_query("SELECT MIN(id) as min_id,MAX(id) as max_id FROM questions ");
$row = mysql_fetch_array($randomparameter );
$random_questin_id=rand($row['min_id'],$row['min_id']);
于 2013-08-01T17:02:52.070 に答える
0

おそらく、配列を使用して質問 ID を格納し、php の rand 関数を使用して、質問 ID のリストのインデックスとなる乱数 (0 からリストのサイズの間) を生成することができます。

int rand ( int $min , int $max )
于 2013-08-01T17:01:01.953 に答える