我想根据学生的分支显示试卷。我在数据库“aptitude”中创建了 5 个表。表格如下:itque、etrxque、extcque、civilque、mechque。
分支名称存储在“注册”数据库中。
如果学生在 IT 部门,则只应显示 IT 的试卷。
但是逻辑上有一些问题。试卷不按学生所在学科展示。
test.php 的代码:
<html>
<body>
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id'])) {
echo '<span style="color:#FFF;text-align:center;"><p class="login">Please <a href="login.php"style="color: #FFFFFF">log in</a> to access this page.</p></span>';
exit();
}
else {
include("menu.php");
}
?>
<?php
$dbc=mysqli_connect("localhost","root","","register");
$query = "SELECT branch FROM user WHERE m_id = '" . $_SESSION['user_id'] . "'";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if ($row != NULL) {
$Branch = $row['branch'];
}
else {
echo '<p class="error">There was a problem .</p>';
}
?>
<form action="./result.php" method="post">
<?php
$connect = mysql_connect("localhost" ,"root","");
mysql_select_db("aptitude");
$query = mysql_query("SELECT * FROM `$Branch` ORDER BY RAND() LIMIT 10 ");
while($rows = mysql_fetch_array($query)):
$q = $rows['Q_no'];
$qus = $rows['Question'];
$a = $rows['answer1'];
$b = $rows['answer2'];
$c = $rows['answer3'];
$d = $rows['answer4'];
$ans = $rows['correct'];
echo" <p> </p>";
echo "<p>Q:- $qus <br></p>";
echo "<p> A <input type=radio name = 'answer[$q]' value = '$a'></input>$a    <br>
";
echo " B <input type=radio name = 'answer[$q]' value = '$b'></input>$b    <br>
";
echo " C <input type=radio name = 'answer[$q]' value = '$c'></input>$c    <br>
";
echo " D <input type=radio name = 'answer[$q]' value = '$d'></input>$d <br><br> </p>";
endwhile;
?>
<center><input name="cmdSubmit" type="submit" id="cmdSubmit" value="Submit"/>
</center>
</form>
</body>
</html>