<?php include "database.php";?>
<?php session_start();?>
<?php
// Getting total rows there in table
$query="SELECT * FROM questions";
$results=$mysqli->query($query) or die($mysqli->error.__LINE__);
$total=$results->num_rows;
$row=$results->fetch_assoc();
//Reading the rows next by next and vice versa
$offset=$row["question_number"];
// when button next is clicked it will fetch the next row
if(isset($_POST["NEXT"])){
$offset++;
}
// if previous is clicked the previous row will be displayed
elseif(isset($_POST["Previous"])){
if($offset>1){
$offset--;
}
}
$sql="select * from questions where question_number=$offset";
$result=$mysqli->query($sql);
if($result->num_rows > 0){
while($row=$result->fetch_assoc()){
?> <!DOCTYPE html>
<html>
<head>
<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"/>
</head>
<body>
<header>
<div class="container">
<h1>PHP Quizzer </h1>
</div>
</header>
<main>
<div class="container">
<div class="current">Question <?php echo $row["question_number"];?> of <?php echo $total;?>
</div>
<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'];?>
</ul>
<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=""/>
</form>
</div>
</main>
<footer>
<div class="container">
Copyright ©2020, PHP Quizzer.
</div> </footer> </body> </html> <?php
}
}
$mysqli->close();
?>
Nuti 0 Newbie Poster
Dani 4,329 The Queen of DaniWeb Administrator Featured Poster Premium Member
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.