Jump to content

passing variable for page pagination problem


gkg1

Recommended Posts

I have a search form on page that send the query to this page via 'GET' action.

the results display fine (in other words I get the results I expect to get) the problem is I can't seem to get the results to go 15 per page into multiple pages (page pagination)

I can't seem to figure out what i am doing wrong on this results page... here is the php code:

[code=php:0]
ob_start();
session_start();
include("header.php");
require("xxxxx/xxxxx.php");
//construct WHERE clauses
if($keywords !== '*'){
$term1 = "keywords = '$keywords'";
}
if ($keywords == '*')
{
$term1 = "(keywords LIKE '%open%' OR keywords LIKE '%closed%')";
}

if($weekday !== '*'){
$term2 = " AND mweekday = '$weekday'";
}
if ($weekday == '*')
{
$term2 = " AND sort IN ('1', '2', '3', '4', '5', '6', '7')";
}

if($city !== ''){
$term3 = " AND mcity = '$city'";
}
if($city == ''){
$term3 = "";
}

if ($state){
$narrowResultsWith = " AND mstate = '$state'";
$zipcode ="";
$starttime ="";
$amPM ="";
}elseif ($zipcode) {
$narrowResultsWith = " AND mzip = '$zipcode'";
$starttime ="";
$amPM ="";
}elseif ($starttime !== '*') {
$narrowResultsWith = " AND mstart = '$starttime'";
$amPM ="";
}elseif ($starttime == '*') {
$narrowResultsWith = "";
$starttime ="";
$amPM ="";
}elseif ($amPM !== '*') {
$narrowResultsWith = " AND startAP ='$amPM'";
$starttime ="";
}elseif ($amPM == '*') {
$narrowResultsWith = "";
$starttime ="";
$amPM ="";       
}else{
$narrowResultsWith = "";           
}

$term4 = $narrowResultsWith;

if($handicap == 'Yes'){
$term5 = " AND handicap = '$handicap'";
}
else
{
$term5 = "";
}

// Default results per-page.
if (!($limit)){
     $limit = 15;}
// Default page value
if (!($page)){
     $page = 0;}
//the query
$numresults = mysql_query("SELECT * FROM meetings
WHERE $term1 $term2 $term3 $term4 $term5");
$numrows = mysql_num_rows($numresults);
// Number of rows returned from above query error messgae.
if ($numrows == 0){
echo("<br><center><li>Sorry there were no results that
matched your search criteria</li></center><br><br>"); }
// Number of results pages.
if ($numrows !== 0){
$pages = intval($numrows/$limit);
// $pages now contains int of pages, unless there is a remainder from division.
// has remainder so add one page
if ($numrows % $limit) {
$pages++;}
// Current page number.
$current = ($page/$limit) + 1; if (($pages < 1) || ($pages == 0)) {
$total = 1;}
// If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;}
// Else total pages is $pages value.
$first = $page + 1;

// The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;}
//If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;}
// If last results page, last result equals total number of results.
// Now we can display results.
$results = mysql_query("SELECT * FROM meetings
WHERE $term1 $term2 $term3 $term4 $term5
ORDER BY 'mcity', 'sort', 'startAP', 'mStart' 
ASC LIMIT $page, $limit");

echo "<table width=\"100%\"><tr><td>Results <b>$first</b> -
<b>$last of $numrows results</b></td></tr></table><br>";
while ($data = mysql_fetch_array($results))
{
echo "results are a table... they are correct so I eliminated code
here to save space...";
}

if ($page != 0) {

// Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("&nbsp;<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\"><< back</a>&nbsp;");}
for ($i=1; $i <= $pages; $i++)
// loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<center><b>Page $i of $total</b></center>");}
// If current page don't give link, just text.
else{
echo("&nbsp;<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a>&nbsp;");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1)
// If last page don't give next link.
{
$next_page = $page + $limit;
echo("&nbsp;<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next >></a>&nbsp;");}
}
if ($numrows > 0)
{
echo "<br><br><center><a href=\"searching.php\">Click here</a> to
return to the search form.</center><br><br>";
}
include("footer.php");
[/code]

Ok what's happenning is I get the page results, the results are then displayed (15 to the page) and at the bottom of the results you get the page links:
1, 2, 3, 4, 5    ---    Page 1 of 5  ---     NEXT

the problem is that when I click on page two or three etc. the next page has no results but has the message

"Sorry there were no results that matched your search criteria"

any help will be greatly appreciated.
Thanks
gkg1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.