0
votes

Im trying to take make a loop to show one question that is stored in the database on the webpage at a time. Then with a button it will go to the next question and so forth.

<?php

$dbServername = ;
$dbUsername = ;
$dbPassword = ;
$dbName = ;

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

?>

<!DOCTYPE html>
<html>

<head>
<title></title>
</head>

<body>

<?php
$sql = "SELECT * FROM `Questionnaire_Questions_Choices` WHERE 1";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);

if ($resultCheck > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo $row['questionnaire_name'] . "&nbsp;&nbsp;&nbsp;&nbsp";
        echo $row['questionnaire_purpose'] . "&nbsp;&nbsp;&nbsp;Question&nbsp";
        echo $row['question_nbr'] . ".&nbsp;";
        echo $row['question_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;Choice&nbsp";
        echo $row['choice_nbr'] . "&nbsp;";            
        echo $row['choice_text'] . "&nbsp;&nbsp;&nbsp;&nbsp";
        echo $row['personality_category'] . "&nbsp;&nbsp;&nbsp;&nbsp";
        echo $row['personality_trait'] . "&nbsp;&nbsp;&nbsp;&nbsp";
        echo $row['personality_points'] . "<br>";
    }
}
?>

this code is currently showing all of the data in the questionnaire database. I want to make a loop to show only one question and its choices at a time with a button to go to the next question. just don't know where to start.

You need to limit the result by restricting it by the question ID. ... WHERE question_nbr = 1. From there, follow a tutorial or two on forms and passing the next question ID. - waterloomatt