HTML
<form name="form1" method="post" action="">
<table width="254" border="0" align="center">
<tr>
<td width="185" height="5"><p align="left">
<label for="textfield"></label>
<?
$sqlretrive = mysql_query("Select * from tb_classes");
$recordcount = mysql_affected_rows();
?>
<select name="classname" id="staffid2" class="form-control" required >
<option value="">Select Class Name</option>
<? while ($row = mysql_fetch_array($sqlretrive)){ ?>
<option value="<?= $row['id'] ?>">
<?= $row['classname'] ?>
</option>
<? }?>
</select>
</p></td>
</tr>
<tr>
<td height="1">
<?
$sqlretrive = mysql_query("Select * from tb_subjects_reg where status =1");
$recordcount = mysql_affected_rows();
?>
<select name="subjectname" id="select" class="form-control" required>
<option value="">Select Subject</option>
<? while ($row = mysql_fetch_array($sqlretrive)){ ?>
<option value="<?= $row['id'] ?>">
<?= $row['subjectname'] ?>
</option>
<? }?>
<label for="subjectname">
</label>
<select name="subjectname" id="subjectname">
</select></td>
</tr>
<tr>
<td height="2"><div align="right">
<input type="submit" name="find" id="find" value="Find">
</div></td>
</tr>
</table>
<table class="table toggle-square" data-filter="#table_search" width="541" border="0" align="center">
<tr align="center" valign="bottom" bgcolor="#FBA774">
<td colspan="4"><input type="submit" name="shuffle" id="shuffle" value="SHUFFLE QUESTIONS" class="form-control"></td>
</tr>
<tr align="center" valign="bottom" bgcolor="#FBA774">
<td width="182"><div align="center">Question Number</div></td>
<td align="center" valign="bottom"><div align="center">Question</div></td>
<td align="center" valign="bottom"><div align="center"></div></td>
<td align="center" valign="bottom"><div align="center"></div></td>
</tr>
<?
$sqlretrive = mysql_query("Select * from tb_addquestion");
$recordcount = mysql_affected_rows();
$i=0;
while ($row = mysql_fetch_array($sqldisplayresult)){
$i++
?>
<tr>
<td><div align="center">
<?= $i ?>
</div></td>
<td width="183"><div align="center"><a href="viewquestion.php?subject=<?= $row['subject'] ?>&class=<?= $row['class'] ?>&number=<?= $row['question_number'] ?>"></a>
<?= $row['question'] ?>
</div></td>
<td width="100"><div align="center"><a href="viewquestion.php?subject=<?= $row['subject'] ?>&class=<?= $row['class'] ?>&number=<?= $row['question_number'] ?>&id=<?= $row['id'] ?>">View Question</a></div></td>
<td width="58"><div align="center"><a href="viewquestion.php?subject=<?= $row['subject'] ?>&class=<?= $row['class'] ?>&number=<?= $row['question_number'] ?>"><img src="img/edit.png" alt="" />Edit </a></div></td>
</tr>
<? } ?>
<a href="viewquestion.php?subject=<?= $row['subject'] ?>&class=<?= $row['class'] ?>&number=<?= $row['question_number'] ?>"></a></td>
<tr>
<td colspan="4">
<div align="right"></div>
</td>
</tr>
</table>
<p> </p>
PHP
<? include('inc/header.php');
?>
<?
include("connect.php");
?>
<?
if (isset($_POST['shuffle'])) {
$classname = $_POST['classname'];
$subjectname = $_POST['subjectname'];
$sqldisplayresult = mysql_query("Select * from tb_addquestion WHERE class = '$classname' and subject='$subjectname' and status = 1 ORDER BY RAND()");
}
//display score for the specified class and subject in the current or specified session and term
if (isset($_POST['find'])) {
$classname = $_POST['classname'];
$subjectname = $_POST['subjectname'];
$sqldisplayresult = mysql_query("Select * from tb_addquestion WHERE class = '$classname' and subject='$subjectname' ");
}
?>
在我对课程和科目进行过滤后,会显示问题列表。
我希望我的随机播放按钮以我点击它的方式工作,它会自动重新洗牌并从数据库中随机选择问题。
答案 0 :(得分:0)
那么为什么不在第一次请求中使用ORDER BY RAND()
的方式呢?
另一种方法是在您从数据库中请求数据后,在PHP中使用shuffle()方法。
在任何情况下,如果您希望shuffle是动态的,您将不得不使用Ajax,也许使用jQuery's .ajax()方法它会更容易