Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,539
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    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>");}} 
    ?>

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>");}} 
    ?>

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •