Pageing problem - user not allowed to work through the pages

Hi all,

I have had this trouble before, and cant work out what it is.

Basically I have the pageing working, the stock showing correctly and the search keyword directing the page, but when I go to page 2 of the pageing, the page refreshes but the stock stays on page 1 and the pageing does too.

foreach ($_REQUEST as $key => $value ) {
if ($selectKeyword=="") {
$find_Search = $find;
$find_Search = strtoupper($find_Search);
} else {
$searching = "yes";
$find_Search = $selectKeyword;
$find_Search = strtoupper($find_Search);

<div id="result_Right_Results">
 //This is only displayed if they have submitted the form
 if ($searching == "yes")
 echo "<p style='position:relative; margin:0px; padding:0px; top:5px; padding-bottom:15px; font-size:26px'>Your Search Keyword: '".$find_Search."'<p>";

 //If they did not enter a search term we give them an error
 if ($find_Search == "")
 echo "<p>You forgot to enter a search term";
 // We preform a bit of filtering
 $find_Search = strip_tags($find_Search);
 $find_Search = trim ($find_Search);

 //echo $find;
 //Now we search for our search term, in the field the user specified


include "PageNavigator.php";

var_dump ("SELECT * FROM tbl_hotels WHERE upper(Nom_Hot) LIKE '%$find_Search%' AND Act_Hot=1");
$sql.= "SELECT * FROM tbl_hotels WHERE upper(Nom_Hot) LIKE '%$find_Search%' AND Act_Hot=1";


$mPageSize = @$HTTP_POST_VARS["txtPageSize"];
if ((!isset($mPageSize))||intval($mPageSize)==0)
            // $mPageSize = @$HTTP_GET_VARS["pagesize"];			
             $mPageSize = $pagesize;
             if ((!isset($mPageSize))||intval($mPageSize)==0)
             $mPageSize = 10;

$mUrl = $PHP_SELF."?pagesize=".$mPageSize.$mConQry_Str."&amp;search=".$find_Search;

$mAbsolutePage = $absolutepage;

if (!isset($mAbsolutePage))
{    // Set $mOffset and absolutepage if not set
        $mAbsolutePage = 1;
		//echo "lee2";
		//echo $mAbsolutePage;
    $mOffset = 0;
}  else {
   $mOffset = ( $mAbsolutePage - 1 ) * $mPageSize;
   //echo "lee3";

$mResult = mysql_query($mQry) or ("Wrong Select Query");
$mRecordCount = mysql_num_rows($mResult);
$mPageCount = intval($mRecordCount / $mPageSize);
if ($mRecordCount % $mPageSize ) $mPageCount++;

if ($mAbsolutePage>$mPageCount) $mAbsolutePage=$mPageCount;
$mOffset = ( $mAbsolutePage - 1 ) * $mPageSize;

if ($mRecordCount == 0)


$mQry .= " LIMIT $mOffset, $mPageSize ";   // Get record set = $mPageSize every time

$mRes = mysql_query($mQry);

if ($mAbsolutePage == 1)
$mPag1 = $mAbsolutePage;
//echo $mAbsolutePage;
$mPag1 = (($mAbsolutePage - 1) * $mPageSize) + 1;
$mPag2 = $mPag1 + ($mPageSize - 1);
if ($mPag2 > $mRecordCount)
$mPag2 = $mRecordCount;

$result=mysql_query($mQry) or die("Wrong Query");

//End of paging

<?php if(!$mRecordCount == 0) { ?>
<div style="position:relative; width:772px; float:left; height:auto; font-size:15px; padding-bottom:10px; padding-left:2px; z-index:10;">
<?=PagNav($mPageSize, $mPageCount, $mAbsolutePage, $mRecordCount, $mQry, $mUrl);?> - Records <?=$mPag1?> to <?=$mPag2?> (of <?=$mRecordCount?>)
<? } ?>

} ?>


if(($i%0)==0 || $i==0 ){ ?>

<? for($j=1; $j<=$cnt; $j++) {
$q=mysql_fetch_assoc($result) or $morevalue=false;
<div class="result_Hotel">
<div class="result_Hotel_Pic"><a href="hotel.php?hotel_ID=<?=$q['Id_Hot']?>&amp;Type=<?=$q['IdType_Hot']?>&amp;Resort=<?=$q['IdRsrt_Hot']?>" title="<?=$q['Nom_Hot']?> - More Info"><img src="<?=$q['Foto1_Hot']?>" width="176" height="118" border="0" /></a></div>
<div class="result_Middle_Section">
<div class="result_Middle_Section_Top"><span style="position:relative; line-height:27px; height:27px; vertical-align:8px"><a href="hotel.php?hotel_ID=<?=$q['Id_Hot']?>&amp;Type=<?=$q['IdType_Hot']?>&amp;Resort=<?=$q['IdRsrt_Hot']?>" title="<?=$q['Nom_Hot']?> - More Info" class="result_Link"><?=$q['Nom_Hot']?></a></span>

&nbsp;&nbsp;<?php $int=$q['IdCat_Hot'];
if (in_array($q['IdCat_Hot'], array(6, 7))) { ?>

<? } else {
if($int>0) { $k=0; while($k<$int) {  ?><img src="site_images/orange_Star_White.jpg" width="21" height="27" /><?php   $k++; } }  ?>
<? } ?>
<div class="result_Middle_Section_Middle_1"><?=$q['Dir_Hot']?></div>
<div class="result_Middle_Section_Middle_2">COMPLIANT WITH THESE STANDARDS</div>
<div class="result_Middle_Section_Bottom">
$x=mysql_query("SELECT distinct(tbl_standards.Id_Stand), tbl_standards.stand_Name, tbl_standards.Id_View, tbl_standards.Nom_Stand FROM tbl_standards LEFT JOIN tbl_hotnstand ON ( tbl_standards.Id_Stand = tbl_hotnstand.Id_Stand ) WHERE tbl_hotnstand.Id_Hot =".$q['Id_Hot']." AND (tbl_standards.Id_View=1)");

while($z=mysql_fetch_assoc($x)){ ?>
<? if ($z['Id_Stand'] == '18' ) { ?>

<? } else { ?>
$imageTag = $z['Nom_Stand'];
$imageTag = str_replace('<?= $icon_Height ?>', $icon_Height, $imageTag);
$imageTag = str_replace('<?= $icon_Width ?>', $icon_Width, $imageTag);
<a href="javascript:popUp('<? echo "standdata.php?srno=$z[Id_Stand]"; ?>','')" title="<?=$z['stand_Name']?>"><?=$imageTag?></a>
<? } ?>
<? } ?>

<div class="gap_Result"></div>
<div class="gap_Line_Result"></div>
<div class="gap_Result"></div>
<? }
// End Build query	


Hi multichild,

First of all I’d find out what $mQry is set to just before you run the query:

echo $mQry; // Find out if the offset is being set correctly.
$mRes = mysql_query($mQry);

Hi fretburner,

On entering the page having used hotel as the search keyword, this is what is echoed out.

SELECT * FROM tbl_hotels WHERE upper(Nom_Hot) LIKE ‘%HOTEL%’ AND Act_Hot=1 LIMIT 0, 10

Then when I select page 2 on the pageing, the page refreshes, but that echo above doesnt.

So there a problem there isnt there, will have a look but may need some help

OK looks like I resolved the issue, by adding

if($_SERVER['REQUEST_METHOD']=='POST' ) { $post=$_POST;   }
elseif($_SERVER['REQUEST_METHOD']=='GET' ) { $post=$_GET; }

at the top of the page


Code is unreadable.

Learn how to use objects, then use a decent pagination library instead of re-inventing the wheel by creating a broken wheel made of sticks and elastic bands.

Take a look at this:

I can’t read code as bad as this, so I’m not even gonna bother trying.

To be slightly less arsey, here’s a couple of brief criticisms:

You are using the deprecated mysql_ functions. Stop it.

Your code is wide open to sql injection attacks. Read up on them. I reckon I could wipe your database just by passing a certain query to your url. You need to understand why this is possible and what you can do to prevent this (best solution: start using prepared statements in PDO at the very least. Even better, use something like Doctrine 2, but this is probably beyond you right now. Google PDO prepared statements).

You are mixing presentation logic (html and css) with your business application logic. This will make it a nightmare to redesign the look of your site in the future. Look into MVC (model view controller) for a good way to start improving this.

You are including files in the middle of your script. You should barely need to use include and require statements anymore - look into autoloading for this. Even better, look into composer and namespaces. Google this stuff yourself.

Your code is very poorly indented, which also makes it horrible to read. Learn how to indent your code so it’s not painful to read through.

You have pointless comments that should be removed. Learn how to use phpdoc style comments instead.

You’ve also got inline css all over the place (bad news because again, it will make your site much harder to redesign, or to just move things about a bit on the page etc - you shouldn’t really use inline css at all if you can help it).

You’re using old school javascript that is bound to the html and bound to your php logic - again, changing a few simple pieces of javascript will be very hard and unpredictable using the methods you’re currently using.

Also, go to this site and READ it. It will make you a far, far better developer. You can start by looking at the database stuff and take it from there:

There. I did more than just say your code is crap. I feel slightly better now.