I'm having trouble getting the id from the URL when i'm switching to another page using the pagination, I need this id from the database to view the contents in the navbar when i switch to another page. When I try to switch to pages the contents in the navbar will not appear. Here is my code
<?php
$limit = 5;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $limit;
$sql = "SELECT * FROM invoice LIMIT $start, $limit";
$result1 = $conn->query("SELECT count(id) AS refNo FROM invoice");
$query = mysqli_query($conn,$sql);
$custCount = $result1->fetch_all(MYSQLI_ASSOC);
$total = $custCount[0]['refNo'];
$pages = ceil($total / $limit);
$previous = $page - 1;
$next = $page 1;
$id = $_GET['id2'];
?>
<h3 style="color:white">Student Schedules</h3>
<label for="course" style="color:white">Invoices And Records<br></label>
<nav aria-label="Page navigation example">
<ul >
<li >
<a href="viewUserSchedule.php?id=<?php $id?>&page=<?= $previous; ?
>">Previous</a></li>
<?php for($i = 1; $i <= $pages; $i ) : ?>
<li ><a href="viewUserSchedule.php?id=<?php $id?
>&page=<?= $i; ?>
"><?= $i ?></a></li>
<?php endfor; } ?>
<li ><a href="viewUserSchedule.php?id=<?php $id?
>&page=<?= $next; ?>">Next</a></li>
</ul>
</nav>
CodePudding user response:
Just change this:
<?php $id?>
to this:
<?= $id ?>
or this:
<?php echo $id ?>
CodePudding user response:
As I can see in your codes, you have simple mistake in your codes. You are using:
<?php $id?>
and for other variables like $previous you are using:
<?= $previous; ?>
So <?= is shortcode for <?php echo and in printing your $id variable you missed the echo So, you should use :
<?php echo $id?>
Or
<?= $id?>
so try this code, and it would work for you:
<h3 style="color:white">Student Schedules</h3>
<label for="course" style="color:white">Invoices And Records<br></label>
<nav aria-label="Page navigation example">
<ul >
<li >
<a href="viewUserSchedule.php?id=<?php echo $id?>&page=<?= $previous; ?>">Previous</a></li>
<?php for($i = 1; $i <= $pages; $i ) : ?>
<li ><a href="viewUserSchedule.php?id=<?php echo $id?>&page=<?= $i; ?>"><?= $i ?></a></li>
<?php endfor; } ?>
<li ><a href="viewUserSchedule.php?id=<?php echo $id?>&page = <?= $next; ?>">Next</a></li>
</ul>
</nav>