top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I Paginate my records in PHP?

0 votes
60 views
How can I Paginate my records in PHP?
posted Jul 15, 2014 by Rahul Mahajan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You need to use Limit query for this.
e.g
<?php

$page=1;
$per_page_records=5;
$find="select * from table_name"; //records count
$exe=mysql_query($find);
$row=mysql_fetch_row($exe);
$total_records=mysql_num_rows($exe);
$total_pages=ceil($total_records/$per_page_records);
if(isset($_GET["page"])
{
$page=$_GET["page"];
$index=$per_page_records*($page-1);
}
$limitqry="select * from table_name limit $index,$per_page_records";
$limitexe=mysql_query($limitqry);
while($row=mysql_fetch_row($limitexe))
{
echo"$row['column_name1']";
}
//pagination code

if($page>1){ echo''
}
else{echo"";}
for($i=0;$i<=$total_pages;$i++)
{
if($page==$i)
{
echo'
'
}
else
{
echo'
'
}}
if($page<$total_pages)
{
echo'
'
}

answer Jul 16, 2014 by Mohit Sharma
Similar Questions
0 votes

I wish to delete records in my database that is older than 3 months.

$todays_date = date('Y-m-d');
$old_records_to_delete = ???

if($old_records_to_delete)
{
include(connect.php);
$sql = "DELETE FROM table WHERE date >= '$old_records_to_delete'";
mysql_query($sql, $connect_db) or die(mysql_error());
}

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...