我想从名为 questions 的表中获取随机 ID 并显示随机行,使用此代码时出现错误
Warning: mysql_fetch_array() expects parameter 1 to be resource
我已经使用 min 和 max 函数来获得随机这里是代码 plz iam 需要它
<?php
session_start();
require_once("scripts/connect_db.php");
$arrCount = "";
if(isset($_GET['question'])){
$question = preg_replace('/[^0-9]/', "", $_GET['question']);
$output = "";
$answers = "";
$q = "";
$sql = mysql_query("SELECT MIN(id) as min_id , MAX(id) as max_id FROM questions ");
$row = mysql_fetch_array(rand($sql['min_id'],$sql['max_id']) ) or die($row."<br/> <br/>".mysql_error());
$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;
}
}
?>
提前谢谢