...

View Full Version : Showing less pages in results



justplaindoug
06-29-2007, 01:17 AM
I am not sure how to search for this exact answer- so forgive me if this is old hat.

I am pulling info from my database (mysql using PHP) and that is working fine. But it shows a metric ton of pages (every page available) taking up a lot of space on a page.

i.e. There are[1457] Listings in the Database Results 1 - 8 of 1457 Page 1 of 183
1 2 3 4 5 6 7 8 9 10 11 (the rest omited so I don't get death threats) 178 179 180 181 182 183 next

I am trying to find out how to limit the numbers shown so that I get a result more closely resembling something like

1 2 3 >> 183 183 or something like that. Anything that doesn't list each page.

Here is the code that shows that particular section


<? if($numberOfRows>8){
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"index.php?query=$query&page=$back_page&limit=$limit&artistselect=$Imagemain2\">back</a> \n");}

for ($m=1; $m <= $pages; $m++) // loop through each page and give link to it.
{
$ppage = $limit*($m - 1);
if ($ppage == $page){
echo("<b>$m</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"index.php?query=$query&page=$ppage&limit=$limit&artistselect=$Imagemain2\">$m</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"index.php?query=$query&page=$next_page&limit=$limit&artistselect=$Imagemain2\">next</a>");}}
?>

If you require any other info or code from the page let me know- but I would really appreciate any help.

TIA
Doug

mlseim
06-29-2007, 03:53 AM
I of course have no way of testing my script idea ...
but even if it doesn't work, it might trigger some
idea in your head about how to do it.



<? if($numberOfRows>8){
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"index.php?query=$query&page=$back_page&limit=$limit&artistselect=$Imagemain2\">back</a> \n");}

// Take current page -10 and +10
// Check for exceeding either end.
$start=$page-10;
if($start < 1){
$start=1;
}
$stop=$page+10;
if($stop > $limit){
$stop=$limit;
}

for ($m=$start; $m <= $stop; $m++) // loop through each page and give link to it.
{
$ppage = $limit*($m - 1);
if ($ppage == $page){
echo("<b>$m</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"index.php?query=$query&page=$ppage&limit=$limit&artistselect=$Imagemain2\">$m</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"index.php?query=$query&page=$next_page&limit=$limit&artistselect=$Imagemain2\">next</a>");}}
?>

hadiman
06-29-2007, 04:57 AM
hope this work for you,
:thumbsup:

<? if($numberOfRows>8){
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"index.php?query=$query&page=$back_page&limit=$limit&artistselect=$Imagemain2\">back</a> \n");}


/*
for ($m=1; $m <= $pages; $m++) // loop through each page and give link to it.
{
$ppage = $limit*($m - 1);
if ($ppage == $page){
echo("<b>$m</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"index.php?query=$query&page=$ppage&limit=$limit&artistselect=$Imagemain2\">$m</a> \n");}
}
*/
//////////////////////////////////////////////////////////////////////////////////////
$limitdisplay = 6; // you know what it is.......
$m = 1;
while ( ($page <= $pages) && ($m <= $limitdisplay) ) {
$ppage = $limit*($m - 1);
if ($ppage == $page){
echo("<b>$m</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"index.php?query=$query&page=$ppage&limit=$limit&artistselect=$Imagemain2\">$m</a> \n");}
$page++;
$m++;
}
//////////////////////////////////////////////////////////////////////////////////////


if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"index.php?query=$query&page=$next_page&limit=$limit&artistselect=$Imagemain2\">next</a>");}}
?>

justplaindoug
06-29-2007, 06:35 PM
First off- thank you both for the quick response.

Both of them kind of garnered the same result.

mlseim- that code showed me the first 8 pages available- but after that- it would only show prev and next.

hadiman- it would show 1 through 6, but after that- if i clicked next whether I was on 7 or 15 it would still be displaying 1-6

I am going to take a closer look at what I have- but any further analysis from php gurus with time on their hands is appreciated.

Doug



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum