I'm currently working on php pagination and I manage to get the code working... my problem now is that each time I click on the NEXT or PREVIOUS button the variable in the url will be no more..
please how do I make the variables already in the url stay fixed why the new pagination variables are added to the url...
My url
www.example.com/profile.php?id=2
When a click on the pagination previous or next button my url will look like
www.example.com/profile.php?pageno=4
My problem is how do I make the id=2 not leave even as I continue to click on the pagination button
www.example.com/profile.php?id=2&pageno=3
www.example.com/profile.php?id=2&pageno=4
www.example.com/profile.php?id=2&pageno=5
Pagination code.... please help me
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 10;
$offset = ($pageno-1) * $no_of_records_per_page;
$conn=mysqli_connect("localhost","skyworld1_sky","uromiUROMI914@#","skyworld1_sky");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$total_pages_sql = "SELECT COUNT(*) FROM phonegap2";
$result = mysqli_query($conn,$total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);
$sql = "SELECT * FROM phonegap2 LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($conn,$sql);
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>email</th>";
echo "<th>fullname</th>";
echo "<th>country</th>";
echo "<th></th></tr>";
while($row = mysqli_fetch_array($res_data)){
//here goes the data
echo "<tr><td>";
echo $row['email'];
echo "</td><td>";
echo $row['fullname'];
echo "</td><td>";
echo $row['country'];
echo "</td><td>";
echo " <input type='submit' value='BUY'>";
echo "</td><tr>";
}
echo "</table>";
mysqli_close($conn);
?>
<ul align="center" class="pagination">
<li><a href="?pageno=1">First</a></li>
<li class="<?php if($pageno <= 1){ echo 'disabled'; } ?>">
<a href="<?php if($pageno <= 1){ echo '#'; } else { echo "?pageno=".($pageno - 1); } ?>">Prev</a>
</li>
<li class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>">
<a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?pageno=".($pageno + 1); } ?>">Next</a>
</li>
<li><a href="?pageno=<?php echo $total_pages; ?>">Last</a></li>
</ul>
Problem
You need the ID field to show in the URL when a user clicks the previous or next links.
Solution
If you have an ID as a GET param you can simply pull it out of the URL and add it to your links in the page.
<a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?id=".$_GET['id']."&pageno=".($pageno + 1); } ?>">Next</a>
Example
In my URL on page load I have -
Then in the PHP page -
<?php
$total_pages = 100;
$pageno = 3;
?>
<a href="<?php echo "?id=".$_GET['id']."&pageno=".($pageno + 1); ?>">Next</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.