The first line of code get the saved session gotten from the checkbox and uses the subjects to select the question of each subject from the database.
if (isset($_SESSION['subject']) && $_SESSION['subject']!="") { $subject = $_SESSION['subject']; $subject = $subject[0]; } else { $subject = 1; }
This line was use to define the total question to be display on the screen and also getting the total questions and the calculation for next and previous
$total_records_per_page = 1; $offset = ($subject >= 1) * $total_records_per_page; $previous_page = $subject >= 1; $next_page = $subject > 1; $adjacents = "2";
While this fetch the question from the database based on the subject selected. $result_count = mysqli_query($conn,"SELECT COUNT(*) As total_records FROM question
WHERE subject = '$subject'");
$total_records = mysqli_fetch_array($result_count); $total_records = $total_records['total_records']; $total_no_of_pages = ceil($total_records / $total_records_per_page); $second_last = $total_no_of_pages - 1; // total page minus 1 $result = mysqli_query($conn,"SELECT * FROM `question` WHERE subject = '$subject' LIMIT $offset, $total_records_per_page"); // die(mysqli_error($conn)); while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $ques = $row['questions']; $optiona = $row['optiona']; $optionb = $row['optionb']; $optionc = $row['optionc']; $optiond = $row['optiond']; $qno = $i + 1; echo $qno .". "; echo $ques .'<br>'; echo "<input type='radio' name='answer'> $optiona .<br>"; echo "<input type='radio' name='answer'> $optionb .<br>"; echo "<input type='radio' name='answer'> $optionc .<br>"; echo "<input type='radio' name='answer'> $optiond .<br>"; } mysqli_close($conn); ?>
And this section works for the pagination with bootstrap
<div style='padding: 10px 20px 0px; border-top: dotted 1px #CCC;'> <strong>Page <?php echo $subject." of ".$total_no_of_pages; ?></strong> </div> <ul class="pagination"> <?php // if($subject > 1){ echo "<li><a href='?subject=1'>First Page</a></li>"; } ?> <li <?php if($subject <= 1){ echo "class='disabled'"; } ?>> <a <?php if($subject > 1){ echo "href='?subject=$previous_page'"; } ?>>Previous</a> </li> <?php if ($total_no_of_pages <= 10){ for ($counter = 1; $counter <= $total_no_of_pages; $counter++){ if ($counter == $subject) { echo "<li class='active'><a>$counter</a></li>"; }else{ echo "<li><a href='?subject=$counter'>$counter</a></li>"; } } } elseif($total_no_of_pages > 10){ if($subject <= 4) { for ($counter = 1; $counter < 8; $counter++){ if ($counter == $subject) { echo "<li class='active'><a>$counter</a></li>"; }else{ echo "<li><a href='?subject=$counter'>$counter</a></li>"; } } echo "<li><a>...</a></li>"; echo "<li><a href='?subject=$second_last'>$second_last</a></li>"; echo "<li><a href='?subject=$total_no_of_pages'>$total_no_of_pages</a></li>"; } elseif($subject > 4 && $subject < $total_no_of_pages - 4) { echo "<li><a href='?subject=1'>1</a></li>"; echo "<li><a href='?subject=2'>2</a></li>"; echo "<li><a>...</a></li>"; for ($counter = $subject - $adjacents; $counter <= $subject + $adjacents; $counter++) { if ($counter == $subject) { echo "<li class='active'><a>$counter</a></li>"; }else{ echo "<li><a href='?subject=$counter'>$counter</a></li>"; } } echo "<li><a>...</a></li>"; echo "<li><a href='?subject=$second_last'>$second_last</a></li>"; echo "<li><a href='?subject=$total_no_of_pages'>$total_no_of_pages</a></li>"; } else { echo "<li><a href='?subject=1'>1</a></li>"; echo "<li><a href='?subject=2'>2</a></li>"; echo "<li><a>...</a></li>"; for ($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) { if ($counter == $subject) { echo "<li class='active'><a>$counter</a></li>"; }else{ echo "<li><a href='?subject=$counter'>$counter</a></li>"; } } } } ?> <li <?php if($subject >= $total_no_of_pages){ echo "class='disabled'"; } ?>> <a <?php if($subject < $total_no_of_pages) { echo "href='?subject=$next_page'"; } ?>>Next</a> </li> <?php if($subject < $total_no_of_pages){ echo "<li><a href='?subject=$total_no_of_pages'>Last ››</a></li>"; } ?> </ul>
The pagination click but doesn't load the next question but href links carry's the questions id on the url (http://localhost/mycbt/pagination.php?subject=1). What can i do?
https://stackoverflow.com/questions/65546275/my-pagination-a-href-not-working-what-can-i-do January 03, 2021 at 11:04AM
没有评论:
发表评论