doujunchi1238 2015-06-17 12:58
浏览 36

我想能够在每次点击随机播放按钮时改变问题

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>&nbsp;</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' ");
    }

    ?>

After I have filtered with class and subject, it shows a list of the questions.

I want my Shuffle button to work in a way that once I click on it , it automatically reshuffles and select the questions randomly from the database.

  • 写回答

1条回答 默认 最新

  • dousongxuan7507 2015-06-17 13:36
    关注

    So why not using ORDER BY RAND() the way you used it in the first request?

    Another way could be to use the shuffle() method in PHP after you've requested your data from the database.

    In any case, if you want the shuffle to be dynamic you'll have to use Ajax, maybe with jQuery's .ajax() method it'll be easier

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)