Saturday, May 31, 2008

Simple paging in php

function prev_pg($current_page,$url)
{
for($i=1;$i<$current_page;$i++)
{
echo " ".$i."|";
}

}
function next_pg($current_page,$url,$total_set,$limits)
{
$total_pages=($total_set/$limits)+1;
for($i=$current_page;$i<=$total_pages;$i++)
{
echo " ".$i."|";
}
}


if(isset($_POST["page_no"]))
$page=$_POST["page_no"];
else
$page=1;
$start=$page-1;
$limits=10;

$sql="SELECT `*` FROM ------------- ";
$name1=mysql_query($sql);
$total_set=mysql_num_rows($name1)




$sql="SELECT -------------------- LIMIT $start ,$limits";
$name=mysql_query($sql);
$row=mysql_fetch_array($name);


prev_pg($page,"tariff.php");
next_pg($page,"tariff.php",$total_set,$limits);

No comments:

Post a Comment