Have an account? Sign in
Login  Register  Facebook
Problems with pagination on join mysql table
Hello there,
I'm having some issue with pagination script. The php page gets an id (katid) from user and displays all articles that correspond with that ID. Since here, everything is ok but, when i tried to implement the pagination class it didn;t do the work. I have sett to group articles by 5 and i'm having 6 articles. The pagination class should "create" 2 pages, the firs one with 5 articles and the second one with 1 article but, the class creates 4 pages and in the first page does not display only 5 articles but all 6 that are in the database. The second, third and fourth page does not display anything.
The query look like this:
if(isset ($_GET['katid'])) {

  
    $katid = intval($_GET['katid']); //make sure its an integer
   // Settings for pagination. faqja=page  
       $faqja = (int) (!isset($_GET["faqja"]) ? 1 : $_GET["faqja"]);
	$faqja = ($faqja == 0 ? 1 : $faqja);
	$perpage = 5;//maksimumi i rrjeshtave per nje faqe
	$startpoint = ($faqja * $perpage) - $perpage;
   
	$sql = "SELECT B.LKatEmri, A.LajmeID AS LajmeID, A.LajmeEmri AS LajmeEmri, A.LajmeLink AS LajmeLink, A.LajmeIntro AS LajmeIntro, A.LajmeTxt AS LajmeTxt, A.LajmeTag AS LajmeTag, A.LajmeImg AS LajmeImg, A.LajmeVideo AS LajmeVideo, A.LajmeAktiv AS LajmeAktiv, A.KatLajmeID AS KatLajmeID FROM lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE A.LajmeAktiv='PO' AND B.LKatID = '$katid' ORDER BY LajmeID ASC LIMIT $startpoint,$perpage";

The pagination class continue with this one:
<div class="artikulllajmi">
			           <?php 
					   require_once ('functions/faqosja.php'); // The pagination class.
					   $result=mysql_query($sql);
					   
	    if(mysql_num_rows($result) > 0) //products found
    {
        while($row = mysql_fetch_assoc($result)) //Loop through the procusts and display them
        {?>
             <div class="lajmifundit" style="border-bottom:1px dotted #0099FF; text-align:justify;">
            <h3 style="margin-bottom:0; font-size:14px; font-weight:700; color: #CC3366; margin-top:2px;"><a href="artikuj.php?lajmeid=<?php echo $row['LajmeID'];?>" /> <?php echo $row['LajmeEmri'];?> </a></h3>
            
<img src="imazhet/artikuj/<?php echo $row['LajmeImg'];?>" width="70" height="70" hspace="2" vspace="2" border="0" align="left" alt="<?php echo $row['LajmeEmri'];?>" title="<?php echo $row['LajmeEmri'];?>" /> 
<p><?php echo $row['LajmeIntro'];?><a href="artikuj.php?lajmeid=<?php echo $row['LajmeID'];?>" />Lexo të plotë...</a></p>
            </div>

             
            <?php
					 }
				  }
				  echo Pages("lajme",$perpage,"katlajme.php?"); // Script that makes pagination appear


Please, help me on this issue!
Thank you!
Started: September 21, 2011 Latest Activity: September 21, 2011 pagination issue
2 Answers
Thank you very much DesignShop. I have resolved that issue thanks to you.
The code that i used is this one (your suggestion and a little modification made by me):
echo Pages("lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE A.LajmeAktiv='PO' AND B.LKatID = '$katid'",$perpage,"katlajme.php?katid=$katid&");

Thanks again!

Posted: Kleidi
In: September 21, 2011

first the query of the content must be the same of the pages ok?
look you can do that:
echo Pages("lajme A LEFT JOIN lajme_kategori B ON A.KatLajmeID = B.LKatID WHERE A.LajmeAktiv='PO' AND B.LKatID = '$katid'",$perpage,"katlajme.php?");

note:not tested

Posted: DesignShop
In: September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer