-1

我目前正在设计一个调查类型的系统,其中系统使用 while 循环显示要投票的人数。不幸的是,我不知道如何创建页面,相反,我只能将整个 while 循环迭代到一个整页脚本中。

这是我的代码:

while($fetch=mysql_fetch_array($query1)){

    //Code here

        while($fetch=mysql_fetch_array($query2)){

            //VERIFY ANSWERS
            if(isset($_POST['voted'])){
                if(in_array($_POST['score('.$fetch['questionID'].')'], $radioValue)){
                }
                else{
                    $missed++;
                }

                $checker = true;
            }
        }

            //CHECKER IF A RADIO BUTTON IS MISSED 
            if($checker==true){
                if($missed==$rows || $missed < $rows && $missed != 0 ){
                    echo "<center><font color=red>All items are required</font><br>";
                }
                else{
                    //Some code here
                }
            }

        $query=mysql_query("SELECT * FROM questions");
        while($fetch=mysql_fetch_array($query)){
            //DISPLAYS QUESTIONS WITH QUESTION NUMBER
                            //Some code here

            //DISPLAYS RADIO BUTTONS FROM 1 to 5    
                            //Some code here
            }
        }

    echo "</table>
    <br><center>
    <input type='submit' name='voted' value='Submit'>
}

所以基本上,我的代码只是一个while循环中的一个while循环

编辑:为了清楚起见,我在问如何仅使用一个脚本将 while 循环迭代分成“页面”。

所以基本上,我想要发生的是:

被提名人 1 展示问题(1 到 9)

下一步按钮

被提名人 2 再次显示问题(1 到 9)

此外,它只会根据 fetch_array 命令收集的项目数重新迭代。

4

3 回答 3

2

您应该LIMIT在 SQL 查询中使用,并仅获取该页面问题列表。
类似于:SELECT * FROM questions LIMIT 0, 10将获取前 10 个问题。

我建议阅读 MySQL 文档:http ://dev.mysql.com/doc/refman/5.0/en/select.html并且不要使用mysql_ * php 函数,它们已被弃用,使用PDOmysqli_*函数

于 2013-03-21T11:28:08.100 回答
0

所以基本上你想要: -

Page 1.  
 PROCESS POST FROM PREVIOUS PAGE (ie none until page 2)  
 Get nominees that need questions answered LIMIT 1.  
 IF NO RESULTS:
    SAY "thank you - all finished"  
 OTHERWISE:
    display nominee details  
    loop through questions 1-9  
    post form to this script -> this will be page 2
于 2013-03-21T11:51:13.077 回答
0

如果我有你的问题,那么我认为你可以这样做:

<?php
   while(...) {
 #your while loop code
?>
your HTML code for showing data 
<?php
 } # terminate while loop 
?>

PHP 代码将位于 PHP 标记之下,而 HTML 将位于 PHP 标记之外。

于 2013-03-21T11:33:57.930 回答