Pagination Displays Everything Rather Than Limit

Discussion in 'PHP' started by scottlpool2003, Oct 2, 2012.

  1. #1
    I've wracked my brains trying to figure out why the script below isn't limiting to 10 items per page. In total there are 26 (encounting) and it displays all 26 items with a link to page 2 and nothing is on page 2 so that part of the script is correct. Have I got the LIMIT $start, $itemsPerPage in the wrong place?

    <?php
    $itemsPerPage = 10;
    
    
    $currentPageNumber = (int) $_GET['page'];
    if(empty($currentPageNumber))
        $currentPageNumber = 1;
    
    $mpnQuery = "SELECT count(id) FROM publication_issue";
    $resultm = mysql_query($mpnQuery) or die(mysql_error());
    $data = mysql_fetch_array($resultm);
    
    $maxPageNumber = ceil($data[0]/$itemsPerPage);
    
    $start = ($currentPageNumber - 1) * $itemsPerPage;
    
    $resultq = mysql_query ("SELECT id,title,tags FROM publication WHERE cat = '$cat' OR tags LIKE '%$search_term_esc%'");
    
    while($rowg = mysql_fetch_array($resultq)){
    $idd = $rowg['id'];
    $title=mysql_real_escape_string($rowg['title']); 
    
    //Get image and category
    	$resulth = mysql_query("SELECT * FROM publication_issue WHERE publication_id = '$idd' LIMIT $start, $itemsPerPage");
    
    //Display results
    while($rowh = mysql_fetch_assoc($resulth)) {
    $img = $rowh['smallimg'];
    $id = $rowh['id'];
    echo "<div class=\"otherpub\"><a href=\"../pubissue.php?id=$id\" title=\"$title\"><img src=\"/uploader/$img\" height=\"130px\" style=\"padding:1px;border:1px solid silver;\" alt=\"$title\"></a></div>";
    
    }
    }
    
    if($currentPageNumber==1){
        echo 'Previous';
    }
    else{
        echo "<a href=\"pubissue.php?id=$issueid&page=" .($currentPageNumber - 1). "\">Previous</a>";
    }
    
    echo ' - ';
    
    if($currentPageNumber==$maxPageNumber){
        echo 'Next';
    }
    else{
        echo "<a href=\"pubissue.php?id=$issueid&page=" .($currentPageNumber + 1). "\">Next</a>";
    }
    
    mysql_close();
    ?>
    PHP:
     
    scottlpool2003, Oct 2, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    shouldn't the LIMIT be on the the query before? You do it when you commented above it where get the image and category. Logically looking at the code it has to go on the query before.
     
    plussy, Oct 2, 2012 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Thanks, but I'd rather keep working on it with advise than pay someone to do it as I'll never improve if I don't tackle these things.
     
    scottlpool2003, Oct 3, 2012 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    Solution here:

     
    scottlpool2003, Oct 3, 2012 IP