Hello,
I am very new in PHP and migrated from ASP, I was searching for Paging and i found very complicated Coding and most are not working.
So I wrote my code and it works fine I checked it with over 3000 Records.
Let me know if any body make any alteration.
<?
$dblink = mysql_connect("localhost", "", "");
mysql_select_db("approvedwebhosts",$dblink);
$query = "select * from admin_log_history";
$result = mysql_query($query, $dblink);
$numrow = mysql_num_rows($result);
$num=0;
if(!isset($pgno))
{
$pgno=1;
}
$currentpage = $pgno;
$pagesize = 10;
$limit = 10;
$pg = $numrow / $pagesize;
for($a = 0; $a < $pg ; $a++)
{
if($a == $pgno - 1)
{
$num = $a * $pagesize;
}
}
$dblink = mysql_connect("localhost", "", "");
mysql_select_db("approvedwebhosts",$dblink);
$query = "select * from admin_log_history limit $num, $limit";
$result = mysql_query($query, $dblink);
$numrow = mysql_num_rows($result);
for($k = 0; $k < $pagesize; $k++)
{
if($k > $numrow - 1)
break;
print(mysql_result($result, $k, "admin_log_history.id")."<br>\n");
}
if($pgno > 1 )
{
print("<br><a href=test2.php?pgno=" . $pgno = $pgno - 1 . ">[<< Previous]</a> ");
}
for($i = 1; $i <= 20; $i++)
{
if($i == $currentpage)
{
print(" ". $i . " ");
}
else
{
print("<a href=test2.php?pgno=" . $i . ">". $i . "</a>\n");
}
}
if($currentpage < $pg)
{
print("<a href=test2.php?pgno=" . $currentpage = $currentpage + 1 . ">[Next >>]</a>");
}
?>