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:
PHP Code:
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:
PHP Code:
<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
This is the pagination class:
PHP Code:
<?php
/**
* @author Ferjolt Ozuni
* @copyright 2010
*/
ob_start();
session_start();
function Pages($tbl_name,$limit,$path)
{
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$adjacents = "2";
$faqja = $_GET['faqja'];
if($faqja)
$start = ($faqja - 1) * $limit;
else
$start = 0;
$sql = "SELECT id FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);
if ($faqja == 0) $faqja = 1;
$prev = $faqja - 1;
$next = $faqja + 1;
$lastpage = ceil($total_pages/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class='pagination'>";
if ($faqja > 1)
$pagination.= "<a href='".$path."faqja=$prev'>« mbrapa</a>";
else
$pagination.= "<span class='disabled'>« mbrapa</span>";
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $faqja)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."faqja=$counter'>$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if($faqja < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $faqja)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."faqja=$counter'>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href='".$path."faqja=$lpm1'>$lpm1</a>";
$pagination.= "<a href='".$path."faqja=$lastpage'>$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $faqja && $faqja > ($adjacents * 2))
{
$pagination.= "<a href='".$path."faqja=1'>1</a>";
$pagination.= "<a href='".$path."faqja=2'>2</a>";
$pagination.= "...";
for ($counter = $faqja - $adjacents; $counter <= $faqja + $adjacents; $counter++)
{
if ($counter == $faqja)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."faqja=$counter'>$counter</a>";
}
$pagination.= "..";
$pagination.= "<a href='".$path."faqja=$lpm1'>$lpm1</a>";
$pagination.= "<a href='".$path."faqja=$lastpage'>$lastpage</a>";
}
else
{
$pagination.= "<a href='".$path."faqja=1'>1</a>";
$pagination.= "<a href='".$path."faqja=2'>2</a>";
$pagination.= "..";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $faqja)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."faqja=$counter'>$counter</a>";
}
}
}
if ($faqja < $counter - 1)
$pagination.= "<a href='".$path."faqja=$next'>perpara »</a>";
else
$pagination.= "<span class='disabled'>perpara »</span>";
$pagination.= "</div>\n";
}
return $pagination;
}
?>
Please, help me on this issue!
Thank you!