Web Hosting Talk







View Full Version : hot to number the pages in the result..?


waturl
08-18-2007, 07:26 AM
Hello,

I can can print "previous - next"

but i need it to be like "previous 1 2 3 4 5 6 7 next"

here is the code how i print the previous and next.



$page = $_GET['page'];
$pagesize = 15;
if ($page == ''){$page=1;}
$start = ($page - 1) * $pagesize;

include "databaseconnexion.php";
mysql_query("select * from databese");
if(mysql_affected_rows() <= 0){
print "there's no data";
}else{
$fullresult = mysql_affected_rows();
$p=mysql_query("select * from database order by id desc LIMIT $start,$pagesize ");
while($row = mysql_fetch_array($p)){
print $row['id'];
//showing the data

}

<a href='link.php?page=<?=$page-1?>'><font color='575757'>previous < |</font></a>

}else{
print "<font color='CCCCCC'>next < |</font>";
}
if( $page*$pagesize < $fullresult){
<a href='home.php?page=<?=$page+1?>'><font color='575757'>| > Next</font></a>
}else{
print "<font color='CCCCCC'>| > Previous</font>";
}


It's just an exemple...hope you can help me..the easy way to number the result.

Thank you

RSMN
08-18-2007, 02:01 PM
Just do a mysql_num_rows() on the result, and divide the result by your page size (15), and then loop it into existance.

i.e.

Result returns 150 rows.

$result = mysql_num_rows(); // 150
$links = $result / $pagesize; // 10
// Do some error checking //
if ($result / $pagesize != 0)
{
$links = $links + 1; // Adds an extra page if we don't have an exact amount of
} // returned results.

while($i <= $links)
{
echo "<a href=\'home.php?page=$i\'>$i</a>";
}

hq12
08-19-2007, 01:16 AM
i was looking for this too. very good posting.

waturl
08-26-2007, 06:44 AM
hello,

anybody could work with this..? it did not work with me, any body can help (explain) ?