Reputation: 63
I have few records in MySQL DB table.
Displayed those records with pagination PREV and NEXT.
Page ids are displaying in url bar.
I don't want them while pagination clicking.
How can i do this?
Here is my code.
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("moodle");
$per_page = 10;
$pages_query = mysql_query("SELECT COUNT('id') FROM question");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT * FROM question LIMIT $start, $per_page");
while($query_row = mysql_fetch_assoc($query)){
echo $query_row['id']."<br />";
}
$prev = $page - 1;
$next = $page + 1;
echo "<a href='pagination.php?page=$prev'>Prev</a> ";
if($pages >= 1){
for($x=1; $x<=$pages; $x++){
echo '<a href="?page='.$x.'">'.$x.'</a> ';
}
}
echo "<a href='pagination.php?page=$next'>Next</a> ";
?>
Upvotes: 0
Views: 699
Reputation: 328
Use id in session and don't display it in url . other method is to use Ajax call in pagination on click of previous or next button . i think these are two simple solutions for you that you can easily manage .
Upvotes: 1