Click to See Complete Forum and Search --> : Max results


sandro27
04-02-2005, 10:20 PM
Hi !!

I am having a problem with the page results.

My database has a lot of data, so in my page results it is showing over 30 pages but I would like to show the first 10 page numbers and then just add one more as I move to the next page number.

Maybe my script will make it clear:


<?
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM accommodation"),0);

$total_pages = ceil($total_results / $max_results);

echo "<strong><font color='#003366' size='2'>Pages: </font></strong>";

if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&area=$area&acc_category_id=$category\"><strong><font size='2'>Previous</font></strong></a>&nbsp;";
}
for($i=1; $i <= $total_pages; $i++ ){
if(($page) == $i){
echo "<font color='#FF6633' size='2'><strong>$i&nbsp;</font></strong>";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&area=$area&acc_category_id=$category\"><strong><font size='2'>$i<br></font></strong></a>&nbsp;";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&area=$area&acc_category_id=$category\"><strong><font size='2'>Next>></font></strong></a>";
}
echo "</center>";
?>

As you can see above it keeps adding page numbers. How can I show only 10 page numbers just like google result page.

Thanks for any help

:o

ShrineDesigns
04-03-2005, 05:50 AM
example:<?php
$pg = $_GET['pg'];
$ppg = 10; // items per page
$total = 100;

if($total > $ppg)
{
for($i = 1; $i <= ceil($total / $ppg); $i++)
{
if($i <= 10 && $i >= 10)
{
// output link to pages in range
}
if($i >= 10)
{
break; // no need to continue looping
}
}
}
?>

sandro27
04-03-2005, 11:13 AM
Thanks for the reply.

One more thing.

The following code shows me I am in the current page:

if(($page) == $i){
echo "<font color='#FF6633' size='2'><strong>$i&nbsp;</font></strong>";
}


How can I use this line of code along with the line you provided ?

The entire code :
<?
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM accommodation"),0);

$total_pages = ceil($total_results / $max_results);

echo "<strong><font color='#003366' size='2'>Pages: </font></strong>";

if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&area=$area&acc_category_id=$category\"><strong><font size='2'>Previous</font></strong></a>&nbsp;";
}
for($i=1; $i <= $total_pages; $i++ ){

if($i <= 10 && $i >= 10){
echo "<font color='#FF6633' size='2'><strong>$i&nbsp;</font></strong>";
}
if($i >= 10)
{
break; // no need to continue looping
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&area=$area&acc_category_id=$category\"><strong><font size='2'>$i</font></strong></a>&nbsp;";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&area=$area&acc_category_id=$category\"><strong><font size='2'>Next>></font></strong></a>";
}
echo "</center>";
?>

If you look into it , you will see the current page will always be 10.

:D

ShrineDesigns
04-03-2005, 05:34 PM
<?php
$pg = $_GET['pg'];
$ppg = 10; // items per page
$total = 100;

if($total > $ppg)
{
for($i = 1; $i <= ceil($total / $ppg); $i++)
{
if($i <= ($pg + 10) && $i >= ($pg + 10))
{
// output link to pages in range
echo ($i == $pg) ? "<b>$i</b>\n" : "<a href=\"page.php?pg=$i\">$i</a>\n";
}
if($i >= ($pg + 10))
{
break; // no need to continue looping
}
}
}
?>