Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem with pagination class with join mysql db
Old 08-29-2010, 10:01 AM Problem with pagination class with join mysql db
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
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"]) ? $_GET["faqja"]);
    
$faqja = ($faqja == $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 + ($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 + ($adjacents 2))
{
if(
$faqja + ($adjacents 2))       
{
for (
$counter 1$counter + ($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 - (+ ($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!
Kleidi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-30-2010, 02:29 AM Re: Problem with pagination class with join mysql db
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
"." is cocatenation in php, you would have to escape it, probably much better not to use it... period!
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 08-31-2010, 01:41 PM Re: Problem with pagination class with join mysql db
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
I have resolved this issue. Was a problem on sql query. I have made this modification and it works now.
PHP Code:
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&"); 
Kleidi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem with pagination class with join mysql db
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17161 seconds with 12 queries