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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 易语言把MYSQL数据库中的数据添加至组合框
    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况