62 lines
4.2 KiB
PHP
62 lines
4.2 KiB
PHP
<?php
|
|
//link to mysql
|
|
$con=mysqli_connect("127.0.0.1:3306","buptStudent","buptStudentlx","buptStudentdb");
|
|
if (!$con){die('Could not connect:' . mysql_error());};
|
|
//mysql_select_db("my_db_test", $con);
|
|
$p = 20;
|
|
$pp = 0;
|
|
$ppp = $p + $pp;//the number of questions
|
|
echo "<div id=\"ppp\" ppp=\"".$ppp."\"></div>\n<div class=\"section\" id=\"hiddenBefore\" style=\"display:none\"><h5> 单选题</h5>\n";
|
|
//创建随机数组
|
|
$randomArray = array_rand(range(1,99),$p+1);
|
|
// for($i = 1;$i <= $p;$i++){
|
|
// echo $randomArray[$i]." ";
|
|
// }
|
|
shuffle($randomArray);
|
|
$count = 0;
|
|
for($i = 1;$i <= $p;$i++){
|
|
$flag = 0;
|
|
$random = $randomArray[$i];
|
|
$result = mysqli_query($con,"SELECT * FROM Persons WHERE num='$random'");
|
|
while($row = mysqli_fetch_array($result)){
|
|
$count += 1;
|
|
echo "当前查询次数:$count, 查询行数: $random, 查询题号: $i";
|
|
//html
|
|
$flag = 1;
|
|
echo "<div class=\"spbq\" name=\"div_e\"><div class=\"biankuang biankuang_1\"></div><div class=\"biankuang biankuang_2\"></div><div class=\"biankuang biankuang_3\"></div><div class=\"biankuang biankuang_4\"></div>";
|
|
echo "<h6 id=\"question_".$i."\">". $i. ".". $row['q'] ."</h6>\n<p>";
|
|
echo "<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"1\" id=\"test". $i. "1\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "1\">". $row['A'] ."</label>\n";
|
|
echo "<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"2\" id=\"test". $i. "2\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "2\">". $row['B'] ."</label>\n";
|
|
echo "<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"3\" id=\"test". $i. "3\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "3\">". $row['C'] ."</label>\n";
|
|
if($row['D']){
|
|
echo "<input class=\"with-gap\" type=\"radio\" name=\"answer_". $i. "\" value=\"4\" id=\"test". $i. "4\" onclick=\"addOne(this)\"/>\n<label for=\"test". $i. "4\">". $row['D'] ."</label>\n";
|
|
}
|
|
echo "</p></div>\n";
|
|
echo "<div class=\"input-field col s12\" style=\"height:1px;overflow:hidden\"><input value=\"".$random."\" type=\"text\" class=\"validate\" style=\"color:#fff\" name=\"question_".$i."\"></div>\n";
|
|
}
|
|
echo $flag;
|
|
if($flag == 0){
|
|
$i--;
|
|
echo $i;
|
|
sleep(0.4);
|
|
}
|
|
}
|
|
|
|
// echo "<!-- </div><div class=\"section\"> --><h5> 二、判断题</h5>";
|
|
// $randomArray = range(1,10);
|
|
// shuffle($randomArray);
|
|
// for($i = 1;$i <= $pp;$i++){
|
|
// $random = $randomArray[$i] + 60;
|
|
// $result = mysqli_query($con,"SELECT q FROM Persons WHERE num='$random'");
|
|
// while($row = mysqli_fetch_array($result)){
|
|
// $j = $i + $p;
|
|
// //echo "<p>".$row."</p>";
|
|
// echo "<div class=\"spbq\" name=\"div_e\"><div class=\"biankuang biankuang_1\"></div><div class=\"biankuang biankuang_2\"></div><div class=\"biankuang biankuang_3\"></div><div class=\"biankuang biankuang_4\"></div><h6 id=\"question_".$j."\">". $j. ".". $row['q'] ."</h6>\n<p><input class=\"with-gap\" type=\"radio\" name=\"answer_". $j. "\" value=\"1\" id=\"test". $j. "1\" onclick=\"addOne(this)\"/>\n<label for=\"test". $j. "1\">正确</label>\n<input class=\"with-gap\" type=\"radio\" name=\"answer_". $j. "\" value=\"2\" id=\"test". $j. "2\" onclick=\"addOne(this)\"/>\n<label for=\"test". $j. "2\">错误</label>\n</p></div>\n";
|
|
// echo "<div class=\"input-field col s12\" style=\"height:1px;overflow:hidden\"><input value=\"".$random."\" type=\"text\" class=\"validate\" style=\"color:#fff\" name=\"question_".$j."\"></div>\n";
|
|
// }
|
|
// }
|
|
|
|
echo "</div>";
|
|
//close linking
|
|
mysqli_close($con);
|
|
?>
|