Is this pagination script correct ( Pagination not working)

Discussion in 'PHP' started by hindlist, Apr 11, 2010.

  1. #1
    The pagination for the following php script is not working. It has next and prev buttons but they are not working and if clicked on next button the page is not going to the next results. I think there might be some error to find out this. Can you pls look at this and point the actual problem. Thank you for all in advance. The variable here are 0 and 1

    <?php
    // $_GET['sub'];
    // $_GET['catg'];

    $myDB = new MySQLDB();
    $sql = "SELECT count(*) FROM hl_adsection
    LEFT JOIN hl_subcategory ON hl_subcategory.scateno = hl_adsection.aidscat
    left join hl_category on hl_adsection.aidcategory = hl_category.cateno
    left join hl_country on hl_country.countryid = hl_adsection.aidcountry
    left join hl_city on hl_city.cityid = hl_adsection.aidcity WHERE hl_adsection.aidstatus = 2
    AND hl_category.catename = '".resetEscapeChar($_GET['catg'])."' AND hl_subcategory.scatename = '".resetEscapeChar($_GET['sub'])."' ";

    // echo $sql;
    if($_GET['country'] != ''){
    $sql .= " AND hl_country.countryname = '".resetEscapeChar($_GET['country'])."'";
    if($_GET['city'] != ''){
    $sql .= " AND hl_city.cityname = '".resetEscapeChar($_GET['city'])."'";
    }
    }
    $googlelimit = 11; $ccount = 0; $paginglimit = 22; $totalRecords = 0;
    $sql .= " ORDER BY hl_adsection.adposted DESC";
    //echo $sql;
    $result = $myDB->executeSQL($sql) or die("could not execute stored proc <br>".mysql_error());
    while ($result_row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $totalRecords = $result_row['count(*)'];
    }
    mysql_free_result($result) or die("could not close result set <br>".mysql_error());
    $myDB->close();

    $pageSize = $paginglimit;
    $pageCount = $totalRecords/$pageSize;
    if ($pageCount > (int)$pageCount)
    {
    $pageCount = (int)$pageCount;
    $pageCount++;
    }

    // ******************************************************** This is the paging starting
    if($_GET['pageno'] > 0){
    $urstr = '<a class="link" href="'.$baseurl.'sub/';
    if(isset($_GET['country']) && $_GET['country'] != '') $urstr .= 'country/'.$_GET['country'].'/';
    if(isset($tcity) && $tcity != '') $urstr .= 'city/'.$tcity.'/';
    if(isset($_GET['catg']) && $_GET['catg'] != '') $urstr .= 'cat/'.$_GET['catg'].'/';
    if(isset($_GET['sub']) && $_GET['sub'] != '') $urstr .= 'sub/'.$_GET['sub'].'/';
    if(isset($_GET['pageno']) && $_GET['pageno'] != '') $urstr .= 'pageno/'.($_GET['pageno']-1);

    echo $urstr.'" onmouseover="javascript: buildSubUrl(0,\''.$_GET['grou'].'\',\'\',\'\',\'\',\'\');">&lt;Prev</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

    //echo '<a class="link" href="'.$baseurl.'sub/country/'.$_GET['country'].'/city/'.$tcity.'/cat/'.$_GET['catg'].'/sub/'.$_GET['sub'].'/pageno/'.($_GET['pageno']-1).'">&lt;Prev</a>&nbsp;&nbsp;';
    // echo '<a class="link" href="'.$baseurl.'sub/pageno='.($_GET['pageno']-1).'&amp;sub='.$_GET['sub'].'&amp;catg='.$_GET['catg'].'&amp;country='.$_GET['country'].'&amp;city='.$_GET['city'].'&amp;grou='.$_GET['grou'].'">&lt;Prev</a>';//subcat
    }
    //echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    if($_GET['pageno']+1 < $pageCount){
    $urstr = '<a class="link" href="'.$baseurl.'sub/';
    if(isset($_GET['country']) && $_GET['country'] != '') $urstr .= 'country/'.$_GET['country'].'/';
    if(isset($tcity) && $tcity != '') $urstr .= 'city/'.$tcity.'/';
    if(isset($_GET['catg']) && $_GET['catg'] != '') $urstr .= 'cat/'.$_GET['catg'].'/';
    if(isset($_GET['sub']) && $_GET['sub'] != '') $urstr .= 'sub/'.$_GET['sub'].'/';
    if(isset($_GET['pageno']) && $_GET['pageno'] != '') $urstr .= 'pageno/'.($_GET['pageno']+1);

    echo $urstr.'" onmouseover="javascript: buildSubUrl(0,\''.$_GET['grou'].'\',\'\',\'\',\'\',\'\');">Next&gt;</a>';

    // echo '<a class="link" href="'.$baseurl.'sub/country/'.$_GET['country'].'/city/'.$tcity.'/cat/'.$_GET['catg'].'/sub/'.$_GET['sub'].'/pageno/'.($_GET['pageno']+1).'">Next&gt;</a>';
    // echo '<a class="link" href="subcategory.php?pageno='.($_GET['pageno']+1).'&amp;sub='.$_GET['sub'].'&amp;catg='.$_GET['catg'].'&amp;country='.$_GET['country'].'&amp;city='.$_GET['city'].'&amp;grou='.$_GET['grou'].'">Next&gt;</a>';
    }
    // ******************************************************** This is the paging ending


    $myDB = new MySQLDB();
    $sql = "SELECT aidno, aidimage, aidcategory, aidcountry, aidcity, aidtitle, aiddescription, aidemailid,
    date_format(hl_adsection.adposted, '%W, %M %d, %Y') as poseteddate FROM hl_adsection
    LEFT JOIN hl_subcategory ON hl_subcategory.scateno = hl_adsection.aidscat
    left join hl_category on hl_adsection.aidcategory = hl_category.cateno
    left join hl_country on hl_country.countryid = hl_adsection.aidcountry
    left join hl_city on hl_city.cityid = hl_adsection.aidcity WHERE hl_adsection.aidstatus = 2
    AND hl_category.catename = '".resetEscapeChar($_GET['catg'])."' AND hl_subcategory.scatename = '".resetEscapeChar($_GET['sub'])."' ";

    //echo $sql;
    if($_GET['country'] != ''){
    $sql .= " AND hl_country.countryname = '".resetEscapeChar($_GET['country'])."'";
    if($_GET['city'] != ''){
    $sql .= " AND hl_city.cityname = '".resetEscapeChar($_GET['city'])."'";
    }
    }
    $googlelimit = 11; $ccount = 0; $paginglimit = 22;
    $sql .= " ORDER BY hl_adsection.adposted DESC limit ".($_GET['pageno'] * $paginglimit).",$paginglimit";


    //echo $sql;
    $tdate = '';
    $result = $myDB->executeSQL($sql) or die("could not execute stored proc <br>".mysql_error());
    while ($result_row = mysql_fetch_array($result, MYSQL_ASSOC)){
    if($tdate != $result_row['poseteddate']){
    $tdate = $result_row['poseteddate'];
    echo '<tr style="height: 10px; background-color: #A0B8C8;"><td align="left" colspan="2"><b>'.$tdate.'</b></td></tr>';
    }
    if($ccount == $googlelimit){
    echo '<tr class="entry-1"><td style="height: 50px;" colspan="2" align="center"><b>&nbsp;</b></td></tr>';
    }
    echo '<tr class="entry-1">';
    echo '<td><span class="textHeader2">';
    //buildAdUrl(pageno, grouval, counval, cityval, catval, subcat){
    //echo '<a class="link" href="adpage.php?sub='.$_GET['sub'].'&amp;catg='.$_GET['catg'].'&amp;country='.$country.'&amp;city='.$_GET['city'].'&amp;grou='.$_GET['grou'].'&amp;pageid='.$result_row['aidno'].'"><b>'.$result_row['aidtitle'].'</b></a></span><br>';
    $urlstr = $baseurl.'add/';
    if($country != '') $urlstr .= 'country/'.$country.'/';
    if($_GET['city'] != '') $urlstr .= 'city/'.$_GET['city'].'/';
    $urlstr .= 'cat/'.$_GET['catg'].'/sub/'.$_GET['sub'].'/pageno/'.$result_row['aidno']; //adpage

    echo '<a class="link" href="'.$urlstr.'" onmouseover="javascript: buildAdUrl('.$result_row['aidno'].', \''.$_GET['grou'].'\', \''.$country.'\', \''.$_GET['city'].'\', \''.$_GET['catg'].'\', \''.$_GET['sub'].'\');"><b>'.$result_row['aidtitle'].'</b></a></span><br>';
    echo '<span class="textDesc">'.substr($result_row['aiddescription'],0,200).'...</span>';
    echo '<br><span style="color:#9999CC;">Category: '.resetEscapeChar($_GET['catg']).'/'.resetEscapeChar($_GET['sub']).'</span>';
    echo '</td>';
    echo '<td width="60" align="center" valign="top"><a class="link" href="javascript: buildAdUrl('.$result_row['aidno'].', \''.$_GET['grou'].'\', \''.$country.'\', \''.$_GET['city'].'\', \''.$_GET['catg'].'\', \''.$_GET['sub'].'\');">';
    if($result_row['aidimage'] == '' || $result_row['aidimage'] == NULL)
    echo '<img border="0" src="'.$baseurl.'images/noImageAvailable.jpg" style="width: 50px; height: 50px;" alt="">';
    else echo '<img border="0" style="width: 50px; height: 50px;" alt="" src="'.$baseurl.'image.php?imageid='.$result_row['aidno'].'">'; echo '</a></td>';
    echo '</tr>';
    $ccount++;
    }
    mysql_free_result($result) or die("could not close result set <br>".mysql_error());
    $myDB->close();

    ?>
    </table>
    <?php
    echo "<br>";
    // ******************************************************** This is the paging starting
    if($_GET['pageno'] > 0){
    $urstr = '<a class="link" href="'.$baseurl.'sub/';
    if(isset($_GET['country']) && $_GET['country'] != '') $urstr .= 'country/'.$_GET['country'].'/';
    if(isset($tcity) && $tcity != '') $urstr .= 'city/'.$tcity.'/';
    if(isset($_GET['catg']) && $_GET['catg'] != '') $urstr .= 'cat/'.$_GET['catg'].'/';
    if(isset($_GET['sub']) && $_GET['sub'] != '') $urstr .= 'sub/'.$_GET['sub'].'/';
    if(isset($_GET['pageno']) && $_GET['pageno'] != '') $urstr .= 'pageno/'.($_GET['pageno']-1);

    echo $urstr.'" onmouseover="javascript: buildSubUrl(0,\''.$_GET['grou'].'\',\'\',\'\',\'\',\'\');">&lt;Prev</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

    //echo '<a class="link" href="'.$baseurl.'sub/country/'.$_GET['country'].'/city/'.$tcity.'/cat/'.$_GET['catg'].'/sub/'.$_GET['sub'].'/pageno/'.($_GET['pageno']-1).'">&lt;Prev</a>';
    // echo '<a class="link" href="subcategory.php?pageno='.($_GET['pageno']-1).'&amp;sub='.$_GET['sub'].'&amp;catg='.$_GET['catg'].'&amp;country='.$_GET['country'].'&amp;city='.$_GET['city'].'&amp;grou='.$_GET['grou'].'">&lt;Prev</a> ';
    }
    //echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    if($_GET['pageno']+1 < $pageCount){
    $urstr = '<a class="link" href="'.$baseurl.'sub/';
    if(isset($_GET['country']) && $_GET['country'] != '') $urstr .= 'country/'.$_GET['country'].'/';
    if(isset($tcity) && $tcity != '') $urstr .= 'city/'.$tcity.'/';
    if(isset($_GET['catg']) && $_GET['catg'] != '') $urstr .= 'cat/'.$_GET['catg'].'/';
    if(isset($_GET['sub']) && $_GET['sub'] != '') $urstr .= 'sub/'.$_GET['sub'].'/';
    if(isset($_GET['pageno']) && $_GET['pageno'] != '') $urstr .= 'pageno/'.($_GET['pageno']+1);

    echo $urstr.'" onmouseover="javascript: buildSubUrl(0,\''.$_GET['grou'].'\',\'\',\'\',\'\',\'\');">Next&gt;</a>';

    //echo '<a class="link" href="'.$baseurl.'sub/country/'.$_GET['country'].'/city/'.$tcity.'/cat/'.$_GET['catg'].'/sub/'.$_GET['sub'].'/pageno/'.($_GET['pageno']+1).'">Next&gt;</a>';
    // echo ' <a class="link" href="subcategory.php?pageno='.($_GET['pageno']+1).'&amp;sub='.$_GET['sub'].'&amp;catg='.$_GET['catg'].'&amp;country='.$_GET['country'].'&amp;city='.$_GET['city'].'&amp;grou='.$_GET['grou'].'">Next&gt;</a>';
    }
    // ******************************************************** This is the paging ending
     
    hindlist, Apr 11, 2010 IP