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 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pagination - Change count

    Hi guys,

    Can anyone possibly help me with the output of the pagination links?
    Its is currently displaying :

    PHP Code:
    Showing results 0 10 of 29
    Next Page 
    I need it to display:
    PHP Code:
    Showing results '1' 10 of 29
    Next Page 


    PHP Code:
    //define the no of rows per page
    $rows_per_page 10;

    $query "SELECT posting_id, vehicle_make, vehicle_model, expired, buyers_city, buyers_state, condition, category, description FROM postings WHERE status='open' ORDER BY expired";

    // Run the query.        
    $result = @mysql_query ($query);
    $total_records mysql_num_rows($result);
    $pages ceil($total_records $rows_per_page);
    mysql_free_result($result);


    // if there are more than 1 page run the query like this
    if (!isset($filter))
      
    $filter 0;
      
    $start $filter $rows_per_page ;
      
      
    $query "SELECT posting_id, vehicle_make, vehicle_model, expired, year, buyers_city, buyers_state, condition, category, description FROM postings WHERE status='open' ORDER BY expired, posting_id DESC LIMIT $start, $rows_per_page";


    //the while loop   
    $result = @mysql_query ($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " $query "<br />\nError: (" mysql_errno() . ") " mysql_error());


    // Fetch and print all the records.
        
    while($row=mysql_fetch_array($result)) 
       {
       
    // get the number of rows
        
    $number mysql_num_rows($result);




    // content goes here  ///



    $showingto = ($start $rows_per_page $total_records) ? $total_records $start $rows_per_page;

    echo
    "<font class=\"gen\">";
    echo 
    "Showing results " $start " - " $showingto " of " $total_records
    echo
    "</font><br><br>";



    //showing the navigation links . (Previous)
    if ($filter 0) {
      
    $previous $filter 1;
      
    $url $_SERVER['PHP_SELF'] . "?filter=$previous"
       echo 
    "<a href=\"$url\" class='gen'>Prev Page</a>&nbsp;|&nbsp;\n";           
    }


    // page numbering links 
    while ($i++<$pages){
        
    $url $_SERVER['PHP_SELF'] . "?filter=" . ($i-1);    
        echo 
    $linknum = (($i-1)==$filter) ? "  $i |" "  <a href=\"$url\" class='gen'>$i</a> |";




    //showing the navigation links . (Next)
    if ($filter $pages 1) {
      
    $next $filter 1;
      
    $url $_SERVER['PHP_SELF'] . "?filter=$next";  
      echo 
    "<a href=\"$url\" class='gen'> Next Page</a>\n"

    Any help would be greatly appreciated

  • #2
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could do this:
    PHP Code:
    echo "Showing results " $start " - " $showingto " of " $total_records
    to this:
    PHP Code:
    echo "Showing results " . (($start=='0')? '1' $start) . " - " $showingto " of " $total_records
    It won't be right though. If it says '0-10', it means you have 11 results. Doing what I'm saying here will mean you have '1-10' with 11 results. If you don't mind that, then go ahead.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi BonRouge,
    Thanks for the reply

    So to get it 'correct' I would need to completely recode (start from scratch)?

  • #4
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry - no.
    Just do this:
    PHP Code:
    echo "Showing results " . ($start+1) . " - " . ($showingto+1) . " of " $total_records
    I think that should work.

    (Maybe I should have some breakfast before I switch on my computer...)

  • #5
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do the same thing here, usually even forget my coffee!

    Ok the result was:
    Showing results 1 - 1 of 29

  • #6
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, that doesn't make sense. If $showingto is 10, then $showingto+1 is 11.
    Maybe someone smarter than me should help you. I'm going for breakfast.

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured it out, sorry my mistake!

    I had placed this line below the echo statement!
    $showingto = ($start + $rows_per_page > $total_records) ? $total_records : $start + $rows_per_page;

    Thanks for your help


  •  

    Posting Permissions

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