Basic pagination example in PHP with MySQL

Below specified basic pagination in PHP with MySQL

if (isset($_GET[“page”])) { $page = $_GET[“page”]; } else { $page=1; };
$start_page = ($page-1) * $cou_per_page;
$sql = “SELECT * FROM page_table LIMIT $start_page, $cou_per_page”;
$rs_result = mysql_query ($sql); //run the query
while ($row = mysql_fetch_assoc($rs_result)) {
<td><?php echo $row[‘page_name’]; ?></td>
<td><?php echo $row[‘page_add’]; ?></td>
$sql = “SELECT * FROM page_table”;
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $cou_per_page);

echo “<a href=’?page=1′>”.’|<‘.”</a> “; // Goto 1st page

for ($i=1; $i<=$total_pages; $i++) {
echo “<a href=’?page=”.$i.”‘>”.$i.”</a> “;
echo “<a href=’?page=$total_pages’>”.’>|’.”</a> “; // Goto last page


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s