dtqf81594 2019-02-16 15:05
浏览 15

PHP限制页数

I have tried many of things, but none of them helped me. I have the following code:

 //Check to see if score is set_error_handler
    if (!isset($_SESSION['score'])){
       $_SESSION['score'] = 0;
    }
    
    if (!isset($_SESSION["number"]) || !count($_SESSION["number"])) {
    $_SESSION["number"] = range(1, 4);
    shuffle($_SESSION["number"]);
    }

//Check if form was submitted
if($_POST){
    $number = $_POST['number'];
    $selected_choice = $_POST['choice'];
    $next = array_pop($_SESSION["number"]);
    $total=2;

    //Get total number of questions
    $query="SELECT * FROM `questions` LIMIT 2";
    $results = $mysqli->query($query) or die($mysqli->error.__LINE__);
    $total=$results->num_rows;

    //Get correct choice
    $q = "select * from `choices` where question_number = $number and is_correct=1";
    $result = $mysqli->query($q) or die($mysqli->error.__LINE__);
    $row = $result->fetch_assoc();
    $correct_choice=$row['id'];



    //compare answer with result
    if($correct_choice == $selected_choice){
        $_SESSION['score']++;
    }

    if($number == $total){
        header("Location: final.php");
        exit();
    } else {
            header("Location: formular1.php?n=".$next."&score=".$_SESSION['score']);
    }
}

This part

$total=2

is what i can't find an solution for it. When quiz nr "2" is showing, after i press submit, "final.php" page apear with results. What i need to do, is that i need to limit number of quizes by number of pages, not by id number.

That's mean when 10 pages was showed for example, then must apear "final.php" page, not when id of page apear.

I'm so confused about that. I have tried so many thing, but none of them working. I know is not so complicated, but for me is. Thank you for understanding me

EDIT: I have tried

SELECT * FROM `questions` LIMIT 2

but don't work

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?