SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limiting pagination results

    Hi Guys,

    i am trying to paginate a specific category but am having trouble with my queries, the bottom part of mu pagination returns the correct links the error is here:

    PHP Code:
            $get_id $_GET['cat_id'];
            
            
    ## browse by category ###########################################################
            
    if ($_GET['cat_id']) {
            
            
    $_GET['cat_id'] = round(abs(mb_strcut($_GET['cat_id'], 010))); 
            
            
    ## cat query ####################################################################
            
    $category_query "SELECT * FROM `categories` WHERE `id`='$get_id'";  
            
    $category_result mysql_query($category_query) or die (mysql_error());    
            
    $category mysql_fetch_array($category_result) or die (mysql_error());
             
            
    // a few vars for the cats...///////////////////////////////////////////////////
            
    $cat_id_2 $category['id'];
            
    $cat_name $category['name'];
                                
            
    // neat table for category...////////////////////////////////////////////////////
                 
            
    echo '<br /><h4>'.$cat_name.'</h4>';
               
            
    ## display.../////////////////////////////////////////////////////////////////
                       
            
    $cat_dis "SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC";  
            
    $cat_res mysql_query($cat_dis) or die (mysql_error()); 
                 
            
    ## Pagination start #############################################################
            
    echo "<center>";
            
    // If current page number, use it 
            // if not, set one! 
            
            
    if(!isset($_GET['page'])){ 
                
    $page 1
            } else { 
                
    $page $_GET['page']; 
            } 
            
            
    // Define the number of results per page 
            
    $max_results 5;         
            
            
    // Figure out the limit for the query based 
            // on the current page number. 
            
    $from = (($page $max_results) - $max_results);  
            
            
    // Perform MySQL query on only the current page number's results 
            
            
    $sql mysql_query("SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC $from$max_results"); 
            
            
    ## Pagination start ############################################################# 
    any help would be appreciated

    Graham

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    whats the error Graham?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i knew i forgot to add something lol

    my pagination links are fine say 20 results, 5 per page 4 pages:

    <<< 1 2 3 4 >>>

    but all my results are on the same page instead of on 4.

    thanks mate

    Graham

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure about your situation but its my own simple one please check
    PHP Code:
        mysql_connect("localhost","root","");
        
    mysql_select_db("dotproject");
        
        
    $perpage 5;
        
        
    $start = (isset($_GET['id'])) ? $_GET['id'] : 0;
        
        
    $TotalRec mysql_num_rows(mysql_query("SELECT * FROM projects"));
        
        
    $select "SELECT * FROM projects LIMIT $start$perpage";
        
    $result mysql_query($select) or die(mysql_error());
        
        
    # Dislay your rows here in the loop
        
    while($rows mysql_fetch_array($result)){
            echo 
    $rows['project_name'] . "=" $rows['project_start_date'] . "<br>";
        }
        echo 
    "<br><br>";
        
        if(
    $start == 0){
            echo 
    "Previous &laquo;";
        }else{
            echo 
    "<a href=\"./prevnext.php?id=" . ($start $perpage) . "\">Previous &laquo;</a>";
        }
        
        echo 
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        
        if(
    $start == $TotalRec 1){
            echo 
    "Next &raquo;";
        }else{
            echo 
    "<a href=\"./prevnext.php?id=" . ($start $perpage) . "\">Next &raquo;</a>";
        } 
    Good luck! It can give you some idea.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    looks like the limit part is failing. Echo out each query to check it and make sure you are using the right result set from the right query in the output loop.

    ie you are using the results from $sql and not $cat_dis ....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi SpikeZ,

    i can echo out $cat_dis fine it displays:

    PHP Code:
    SELECT FROM `uploaded_filesWHERE `cat_id`='1' ORDER BY `date_addedDESC 
    but when i echo out the $sql nothing at all is printed.

    cheers mate

    Graham

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    If you are doinf echo $sql it wont as it's a system resource not a string.
    PHP Code:
    $sql_str ="SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC $from$max_results";

    $sql =  mysql_query($sql_str);
    echo 
    $sql_str
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it fixed thanks for your help mate

    Graham


Bookmarks

Posting Permissions

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