0

I have a website developed using PHP PDO programming. In this website there is one page where the details of holiday packages is listed from database along with pagination. My problem is only 6 records from database is loading in the page, but the pagination shows more than one page. Actually I am using PDO for the first time and I can't manage this problem.

Here is my code

index.class (all database functions are written here)

<?php
include_once "class/common.php";
class INDEX {
var $doAction;  
var $msg;
var $objScr;
var $objCommonFunc;     // This is common function object.
var $rsltInfo;          // A common result set used by this class in various queries.
var $rsltOp;            // A common result set used by this class in various queries.
var $arrSysVar;         // Array that stores the System Variable those are used in screen.

// Other variables
var $adminEmail;
var $arrMetaContent;    // For storing content and meta information.
var $leftMenuId;        // Recid of 'menugroup' table for managing leftbar.
var $rightMenuId;       // Recid of 'menugroup' table for managing rightbar.
var $menuPos;   

function getHolydays($rgnId,$start_from, $record_per_page){

    $qrySel = "SELECT h.recid recid, h.regionid regionid, h.name name, h.subtitle subtitle, h.txtDays txtDays, h.txtNights txtNights, h.pricingfrom pricingfrom, h.thumb_img thumb_img 
    FROM holydays h";
    if($rgnId!=0){ $qrySel.= " WHERE h.regionid=".$rgnId; }
    $qrySel .=" LIMIT $start_from,$record_per_page";
    $objDbResult = $this->rsltInfo->getResult($qrySel);
    return $objDbResult;
}

function getHolydaysPagntnCount($rgnId){

    $qrySel = "SELECT h.recid recid, h.regionid regionid, h.name name, h.subtitle subtitle, h.txtDays txtDays, h.txtNights txtNights, h.pricingfrom pricingfrom, h.thumb_img thumb_img 
    FROM holydays h";
    if($rgnId!=0){ $qrySel.= " WHERE h.regionid=".$rgnId; }
    //echo $qrySel ;
    $objDbResult = mysql_query($qrySel);
    return $objDbResult;
}
}
$objScr = new INDEX();
?>

international-holidays.php

            <?php $active_menu = 'Holidays'; 
        include_once("index.class.php");
        include_once 'header.php';
        $objScr = new INDEX();

        //$region_name="";
        //if($_REQUEST['mcId'])$mcId=$_REQUEST['mcId'];
        $rgnId=0;
        if($_REQUEST['rgnId'])$rgnId=$_REQUEST['rgnId'];

        if($_REQUEST['pgId'])
        $pgId=$_REQUEST['pgId'];
        $start_from=!empty($_REQUEST['page'])?$_REQUEST['page']:0;
        //echo $start_from;
        $record_per_page=6;



        $rsltrgn = $objScr->getRegionname();
        $rsltsdrgn = $objScr->getRegionname();
        $rsltholyDetails = $objScr->getHolydays($rgnId,$start_from, $record_per_page);
        $holydetailscount = mysql_numrows($objScr->getHolydayscount());

        $holydaycount = mysql_numrows($objScr->getHolydaysPagntnCount($rgnId));
        $total_pages = ceil($holydaycount/$record_per_page);

        $rsltbannerDets= $objScr->getbannerImg($rgnId);
        $rowbannerdts = $rsltbannerDets->fetchAssoc();
        ?>              
        <div class="col-md-8 col-sm-12 col-8">
        <div class="right">
        <div class="pagination-wrp clearfix">
        <nav class="nav-pagination">
        <?php                                //Here is the code for pagination
        if($total_pages>0){?>

        <ul class="pagination">
        <?php if($pgId>1){?>
        <li class="active"> <?php $prvpages=$start_from-6; $prev = ($pgId - 1); ?> 
        <a href="international-holidays-details.php?<?php echo "page=".$prvpages."&rgnId=".$rgnId."&pgId=".$prev; ?>" aria-label="Previous">
        <img src="images/left-arrow.svg" alt=""></a></li>
        <?php }?>
        <?php
        if($pgId!="" && $pgId!=1){ $spage=$pgId-1; }else{ $spage=1; $pgId=1; }
        $maxPages=5;
        $maxDisplayPage = $pgId + $maxPages - 1;

        if($total_pages-$spage<5){ $spage=$total_pages-5; }
        if($spage<=0){ $spage=1; }

        for($i=$spage;$i<=min($maxDisplayPage, $total_pages);$i++){

        if($i==1){ $st=0; }
        else{
        $st = ($i - 1) * $record_per_page;
        }
        ?>
        <li <?php if($i==$pgId){?> class="active" <?php }?>>
        <a href="international-holidays-details.php?<?php echo "page=".$st."&rgnId=".$rgnId."&pgId=".$i; ?>" >
        <?php echo $i; ?></a>
        </li>

        <?php 
        }

        ?>  
        <li class="active"><?php $nextpages=$start_from+6; if($pgId<$total_pages){ $next = ($pgId + 1); ?> 
        <a href="international-holidays-details.php?<?php echo "page=".$nextpages."&rgnId=".$rgnId."&pgId=".$next; ?>" aria-label="Next">
        <img src="images/right-arrow.svg" alt=""> </a></li> 
        <?php }?></ul><?php }?>

        </nav>
        </div>

        <?php
        if($holydetailscount > 0) {
        while($rowhly = $rsltholyDetails->fetchAssoc())
        {
        //$catgryname=str_split("Hello",3);

        ?>
        <div class="col-sm-6 wow fadeInUp">              
                                         //Here the holiday packages as shown in boxes.
        <a href="international-holidays-details.php?holyId=<?php echo $rowhly['recid']; ?>" class="offer-thumb">
        <div class="offer-img"><img src="../sysimages/origimages/<?php echo $rowhly['thumb_img']; ?>" class="w-100" alt=""></div>
        <div class="details clearfix">
        <div class="title"><?php echo $rowhly['name']; ?><span><?php echo $rowhly['subtitle']; ?> </span></div>
        <div class="price"><span>aed <?php echo $rowhly['pricingfrom']; ?></span>
        <?php echo $rowhly['txtDays']; ?> days &nbsp;<?php echo $rowhly['txtNights']; ?> night</div>
        </div>
        </a>
        </div>
        <?php } }?>


        </div>
        </div>

The same code works perfectly in other page. The thing is the pagination shows 5 pages, but when i click on any page for example 2, it doesn't load the 2nd page rather it shows the first page itself. I didn't understand what is happening. This code has been developed by someone else and my task is to do some updates on this. Can anyone please help me.. I really needed to get this done.

Aishwaryas
  • 633
  • 2
  • 18
  • 44
  • 2
    $holydetailscount = mysql_numrows($objScr->getHolydayscount()); please check this line . it should be `mysql_num_rows($objScr->getHolydayscount())` – prakash tank May 08 '18 at 06:46
  • Same thing on the $holydaycount – Joseph_J May 08 '18 at 06:50
  • That is right. But if that line is not correct it is not supposed to show the results right? Anyway it is not showing any errors. As you said I changed to `mysql_num_rows` but its still the same..not working. – Aishwaryas May 08 '18 at 06:54

1 Answers1

-1

What about if you use this pluggin? In my case it was very helpfull.

https://mottie.github.io/tablesorter/beta-testing/example-pager-custom-controls.html

Or you can just do it manually using mysql.

Pagination using MySQL LIMIT, OFFSET

  • If I have done the whole development, I should have used any of these plugins. But unfortunately, its developed by someone else, and the whole thing is completely developed and my task is do some updations only..!! Thanks for your reference. – Aishwaryas May 08 '18 at 06:56
  • I just edited again the answer... I don't understand why you would give me a negative puntuation... It's not a bad answer. – Ricard Espinàs Llovet May 08 '18 at 07:07
  • 1
    I didn't give you any negative.. It is by someone else I think. I appreciate your answer. – Aishwaryas May 08 '18 at 07:23