任何人都知道如何创建方法提交帖子和下面的编码查询?因为它循环可以有人给我一个查询的例子吗?我已经创建了查询但我不知道如何创建提交以找到答案,在提交按钮后它可以显示哪一个是错误的答案和总分用户正确回答
<?php
include "checklogin.php";
$query1 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=0 AND q_id <=3 order by rand() limit 1");
$query2 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=4 AND q_id <=6 order by rand() limit 1");
$query3 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=7 AND q_id <=9 order by rand() limit 1");
$query4 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=10 AND q_id <=12 order by rand() limit 1");
$query5 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=13 AND q_id <=15 order by rand() limit 1");
$query6 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=16 AND q_id <=18 order by rand() limit 1");
$query7 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=19 AND q_id <=21 order by rand() limit 1");
$query8 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=22 AND q_id <=24 order by rand() limit 1");
$query9 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=25 AND q_id <=27 order by rand() limit 1");
$query10 = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=28 AND q_id <=30 order by rand() limit 1");
?>
<form action ="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method ='POST'>
<table border ='0' align ='left'>
<tr><th>Examination Question</th></tr>
<?php
//question 1
if($row = mysql_fetch_array($query1)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 2
if($row = mysql_fetch_array($query2)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 3
if($row = mysql_fetch_array($query3)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 4
if($row = mysql_fetch_array($query4)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 5
if($row = mysql_fetch_array($query5)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 6
if($row = mysql_fetch_array($query6)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 5
if($row = mysql_fetch_array($query7)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 5
if($row = mysql_fetch_array($query8)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 5
if($row = mysql_fetch_array($query9)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
<?php
//question 5
if($row = mysql_fetch_array($query10)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
?>
答案 0 :(得分:0)
如果我说得对,你应该改变数组的变量:
<?php
include "checklogin.php";
$query = []
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=0 AND q_id <=3 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=4 AND q_id <=6 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=7 AND q_id <=9 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=10 AND q_id <=12 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=13 AND q_id <=15 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=16 AND q_id <=18 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=19 AND q_id <=21 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=22 AND q_id <=24 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=25 AND q_id <=27 order by rand() limit 1");
$query[] = mysql_query("SELECT * FROM `mcq_questions` WHERE q_id >=28 AND q_id <=30 order by rand() limit 1");
然后循环:
foreach($query as $q){
if($row = mysql_fetch_array($q)){
echo "<tr><td>$row[q_detail]</td></tr>";
echo "<tr><td><select name ='Question_1'>
<option value='empty'></option>
<option value='A'>$row[option_a]</option>
<option value='B'>$row[option_b]</option>
<option value='C'>$row[option_c]</option>
td></tr>";}
}
这只是一种方法。