<?php include  "database.php";?> 
             <?php session_start();?> 

            // Getting total rows there in table
            $query="SELECT * FROM questions";
            $results=$mysqli->query($query) or die($mysqli->error.__LINE__);
            //Reading the rows next by next and vice versa

            // when button next is clicked it will fetch the next row
            // if previous is clicked the previous row will be displayed
            $sql="select * from questions where question_number=$offset";

            if($result->num_rows > 0){


                    ?> <!DOCTYPE html> 
                    <meta charset="utf-8"> 
                    <title> PHP Quizzer</title> 
                    <link rel="stylesheet" href="css/style.css" type="text/css"/> 
                    <link rel="stylesheet" href="style.css" type="text/css"/> 
                    <div class="container">
                    <h1>PHP Quizzer </h1> 
                    <div class="container"> 
                    <div class="current">Question <?php echo $row["question_number"];?> of <?php echo $total;?> 
                    <p class="question"> 
                    <?php echo $row["question_number"].".".$row['text'];?> </p>
                    <form method="post" action="question2.php"> 
                    <ul class="choices"> 
                    <li><input name="choice" type="radio" value="A"/><?php echo $row['A'];?> 
                    <li><input name="choice" type="radio" value="B"/><?php echo $row['B'];?> 
                    <li><input name="choice" type="radio" value="C"/><?php echo $row['C'];?> 
                    <li><input name="choice" type="radio" value="D"/><?php echo $row['D'];?> 
                    <input type="submit" value="submit"/> 
                    <input type="submit" value="Previous" name="Previous"/> 
                    <input type="submit" value="NEXT" name="NEXT"/> 
                    <input type="hidden"  name="offset" value=""/> 
                    <div class="container">
                            Copyright ©2020, PHP Quizzer.
                        </div> </footer> </body> </html> <?php
  // Get all rows that exist in table
    $query="SELECT * FROM questions";
    $results=$mysqli->query($query) or die($mysqli->error.__LINE__);

    // If one or more rows exist
   if($result->num_rows > 0){

           // Loop through each row of questions, storing it in the $row variable for each loop iteration

            // Print out the question
            echo $row["question_number"].".".$row['text'];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.