首页 > 解决方案 > 从带有 id 的 Next 按钮更改页面

问题描述

我正在做一个程序,其中我有几个带有 ID 的练习(例如 Id = 1、2、3 ...)我想做的是,一旦用户在练习,他可以按下 Next 按钮并带他进行下一个练习,例如 id + 1。

下面我展示我所做的。你能帮助我吗?

这是我修改后的问题,现在可以了:

<?php
include_once("functions.php");

// Start the session
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project";

$conn = new mysqli($servername, $username, $password, $dbname);
/*echo*/ $id=$_GET['id']; // Current question
$sql = "SELECT * FROM exercises where exercise_id='$id'";
$result = $conn->query($sql); /*Check connection*/


$question_ids = [];
$result2 = doSearch($conn, 'exercise_id');
while($row = $result2->fetch_assoc()) {
    array_push($question_ids,  $row["exercise_id"]);
}
$order = $_GET['order'];
$next_question_id = -1;
$next_question_order = $order + 1;
if (count($question_ids) >= $next_question_order) {
    $next_question_id = $question_ids[$order];
}

?>

<div id="centered_B" class="header">

    <?php
    $row = $result->fetch_assoc();

    ?>

    <p><?php echo $row["exercise_id"] . ". " . $row["text"]?></p>
    <img width="603" height="auto" src="<?php echo $row["image_path"]?>"><br/><br/>

    <form action='' method='post'>
        <input type="radio" name="choice" value= "1" /><img src="<?php echo $row["image_path_A"] ?>"/><br>
        <input type="radio" name="choice" value= "2" /><img src="<?php echo $row["image_path_B"] ?>"><br>
        <input type="radio" name="choice" value= "3" /><img src="<?php echo $row["image_path_C"] ?>"><br>

    <br><br><br><!--- Select difficulty --->

    <p2>Select difficulty level:</p2>

    <form action='' method='post'>
        <select name="choose" id="choose">>
        <option value="1" <?php if($row["difficulty"]=="1") { echo "selected"; } ?> >1</option>
        <option value="2" <?php if($row["difficulty"]=="2") { echo "selected"; } ?> >2</option>
        <option value="3" <?php if($row["difficulty"]=="3") { echo "selected"; } ?> >3</option>
        <option value="4" <?php if($row["difficulty"]=="4") { echo "selected"; } ?> >4</option>
        <option value="5" <?php if($row["difficulty"]=="5") { echo "selected"; } ?> >5</option>
    </select>

    <br><br><br>


        <input class="buttonSubmit" type="submit" name="submit" value="Submit">
        <?php
        if ($next_question_id >= 0) {
        ?>
            <a href="?id=<?php echo $next_question_id; ?>&order=<?php echo $next_question_order; ?>" class="buttonNext" >Next Question</a>
        <?php
        }
        ?>

    </form>

</div><!--- end of centered_B div --->


<?php

if (isset($_POST['submit'])) {
    $user_id = $_SESSION['user_id'];
    $user_check_query = "SELECT * FROM users WHERE id='$user_id'";
    if(isset($_POST['choice'], $_POST['choose'])){
            $choice_answer=$_POST['choice'];
            $difficulty=$_POST['choose'];
//      */$user_id = $_SESSION['user_id'];*/
            $query = "INSERT INTO answers (exercise_id_fk, student_id, difficulty_student, choice_answer) VALUES ('$id','$user_id', '$difficulty', '$choice_answer')";
            $sql=mysqli_query($conn,$query);

    }
}
?>

标签: javascriptphphtml

解决方案


也许这可以帮助你:

var i=$_GET['id']){;

function getNext()
{
    var = var + 1; //increase var by one
return var;
}</script>

<button class="buttonNext" onclick="getNext" >Next Question</button>

推荐阅读