Jump to content

Archived

This topic is now archived and is closed to further replies.

mjwarner

Pagination Help! With Search Result Variables...

Recommended Posts

Hi,

I have a problem and Its been bugging me for week and no matter what I do I cant seem to find the answer,

I have a search script which gets 2 variable posted from the page before and this sets what results someone is looking to retrieve from the database.

I have a pagination script in place on the page which is currently set at 2 for testing. Its searchs the DB and show the results. FINE.

But if there are more than 2 results and you have to click on the NEXT link or PAGE 2, you lose the posted Variables and you get 2 errors:

Notice: Undefined index: img_title in /home/www/markwarner.awardspace.com/search.php

Notice: Undefined index: img_location in /home/www/markwarner.awardspace.com/search.php

Basically these are saying the variables dont exist.

How can I get the variables from page to page?? Or is there something in my script I have done wrong?

[code]<?php
error_reporting(63);
include("./imgtag.php");


$limit = 2;

$page = 0;
   

$search_title = $HTTP_POST_VARS["img_title"];
$search_location = $HTTP_POST_VARS["img_location"];


$numresults = mysql_query("SELECT * FROM mjwarner_litter WHERE img_title LIKE '%".$search_title."%' OR img_title2 LIKE '%".$search_title."%' AND img_location LIKE '%".$search_location."%' AND 1");


$numrows = mysql_num_rows($numresults);

if ($numrows == 0){
    echo("No results found matching your Search");
    exit();}

$pages = intval($numrows/$limit);


if ($numrows % $limit) {
$pages++;}

$current = ($page/$limit) + 1;

if (($pages < 1) || ($pages == 0)) {
$total = 1;}

else {
$total = $pages;}
$first = $page + 1;

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;}

else{
$last = $numrows;}


?>
<center><h2>Search Results</h2></center>
<table width="100%" border="0">
<tr>
  <td width="50%" align="left">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
  </td>
  <td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
  </td>
</tr>
<tr>
  <td colspan="2" align="right">&nbsp;

  </td>
</tr>
<tr>
  <td colspan="2" align="right">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&amp;page=<?=$page?>&amp;limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&amp;page=<?=$page?>&amp;limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&amp;page=<?=$page?>&amp;limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&amp;page=<?=$page?>&amp;limit=50">50</a>
  </td>
</tr>

</table>
<?php

$query = mysql_query("SELECT * FROM mjwarner_litter WHERE img_title LIKE '%".$search_title."%' OR img_title2 LIKE '%".$search_title."%' AND img_location LIKE '%".$search_location."%' ORDER BY img_dateadd ASC LIMIT $page, $limit");
while ($img_info = mysql_fetch_array($query))

{

$link  = "bigimage.php?";
$link .= "file=" . $img_info['img_file'] . "&";             
$link .= "descr=" . urlencode($img_info['img_descr']) . "&"; 
$link .= "height=" . $img_info['img_height'] . "&";         
$link .= "width=" . $img_info['img_width'] . "&";           
$link .= "bytes=" . $img_info['img_bytes'] . "&";           
$link .= "type=" . $img_info['img_type'] . "&";           
$link .= "title=" . $img_info['img_title']. "&";         
$link .= "title2=" . $img_info['img_title2'] . "&";           
$link .= "ped=" . $img_info['img_ped'] . "&";         
$link .= "dogs=" . $img_info['img_dogs'] . "&";                     
$link .= "parents=" . $img_info['img_parents'] . "&";         
$link .= "inject=" . $img_info['img_inject'] . "&";           
$link .= "price=" . $img_info['img_price'] . "&";           
$link .= "alt=" . $img_info['img_alt'] . "&";           
$link .= "location=" . $img_info['img_location'] . "&";           
$link .= "you=" . $img_info['img_you'] . "&";           
$link .= "email=" . $img_info['img_email'] . "&";           
$link .= "phone=" . $img_info['img_phone'] . "&";           
$link .= "bdd=" . $img_info['img_bdd'] . "&";           
$link .= "bmm=" . $img_info['img_bmm'] . "&";           
$link .= "byy=" . $img_info['img_byy'] . "&";             
$link .= "rdd=" . $img_info['img_rdd'] . "&";           
$link .= "rmm=" . $img_info['img_rmm'] . "&";           
$link .= "ryy=" . $img_info['img_ryy'] . "&";     



?><p><table width="600" height="71" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="26" height="26"><img src="images/BoxTopLeft.gif" alt="tl" width="26" height="26" /></td>
    <td width="548" background="images/BoxTop.gif"><img src="images/BoxTop-PuppzOnline.gif" width="157" height="26" /></td>
    <td width="32"><img src="images/BoxTopRight.gif" alt="tr" width="26" height="26" /></td>
  </tr>
  <tr>
    <td height="19" background="images/BoxLeft.gif"></td>
   


<td>

<table width="550" height="65" border="0">
  <tr>
    <td width="160"><?php

echo "<a href=\"$link\" onclick=\"bigimage.php?('{$img_info["img_file"]}'); return false;\">";


echo img_tag($img_info["img_file"], array("x"=>"135"));

?></td>
    <td width="380"><?php



echo "</a><b>".$img_info["img_title"]." ".$img_info["img_title2"]."<hr><br><b>
Location: ".$img_info["img_location"]."<br><b>
Dogs: ".$img_info["img_dogs"]." <b>
Parents Viewable: ".$img_info["img_parents"]."<br><b>
Date Ready: ".$img_info["img_rdd"]."/".$img_info["img_rmm"]."/".$img_info["img_ryy"]."<br><b>     Price: £".$img_info["img_price"]."";?></td>
  </tr>
</table>
 









</td>
 


</td>
    <td background="images/BoxRight.gif"></td>
  </tr>
  <tr>
    <td height="21"><img src="images/BoxBottomLeft.gif" alt="bl" width="26" height="26" /></td>
    <td background="images/BoxBottom.gif"></td>
    <td><img src="images/BoxBottomRight.gif" alt="br" width="26" height="26" /></td></table></p>
<?php
}
?>
<p align="center">
<?php
if ($page != 0) {
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a>    \n");


}

for ($i=1; $i <= $pages; $i++)
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");}
else{
echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");


}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) {
$next_page = $page + $limit;
echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");


}
?>[/code]

Hope someone can see a solution.

Thanks

Mark

Share this post


Link to post
Share on other sites
You must include the variables in the URL too, so this code

[code]<?php
if ($page != 0) {
  $back_page = $page - $limit;
  echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a>    \n");
}

for ($i=1; $i <= $pages; $i++) {
  $ppage = $limit*($i - 1);
  if ($ppage == $page){
      echo("<b>$i</b> \n");
  }
  else{
      echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");
  }
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) {
  $next_page = $page + $limit;
  echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");
}
?>[/code]

Should look like this:

[code]<?php
if ($page != 0) {
  $back_page = $page - $limit;
  echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit&img_title=$search_title&img_location=search_location\">back</a>    \n");
}

for ($i=1; $i <= $pages; $i++) {
  $ppage = $limit*($i - 1);
  if ($ppage == $page){
      echo("<b>$i</b> \n");
  }
  else{
      echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit&img_title=$search_title&img_location=search_location\">$i</a> \n");
  }
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) {
  $next_page = $page + $limit;
  echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit&img_title=$search_title&img_location=search_location\">next</a>\n");
}
?>[/code]

You'll also need to capture these at the top of your script as currently you have $HTTP_POST_VARS but you'll be using $HTTP_GET_VARS for these.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.