Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-29-2007, 12:17 AM   PM User | #1
justplaindoug
New Coder

 
Join Date: Jan 2006
Posts: 52
Thanks: 2
Thanked 0 Times in 0 Posts
justplaindoug is an unknown quantity at this point
Showing less pages in results

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

PHP Code:
<? 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
justplaindoug is offline   Reply With Quote
Old 06-29-2007, 02:53 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.

PHP Code:
<? 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>");}} 
?>
mlseim is offline   Reply With Quote
Old 06-29-2007, 03:57 AM   PM User | #3
hadiman
New to the CF scene

 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hadiman is an unknown quantity at this point
hope this work for you,

PHP Code:
<? 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>");}} 
?>
hadiman is offline   Reply With Quote
Old 06-29-2007, 05:35 PM   PM User | #4
justplaindoug
New Coder

 
Join Date: Jan 2006
Posts: 52
Thanks: 2
Thanked 0 Times in 0 Posts
justplaindoug is an unknown quantity at this point
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
justplaindoug is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:58 PM.


Advertisement
Log in to turn off these ads.