Jump to content

Multi dropdown boxes -- Pagination not working


modigy

Recommended Posts

Hey All,

I've used a tutorial here and some info from some of the other member's post to put together a FULLTEXT search with pagination...

Now I'm trying to get multiple dropdown boxes to give me a results page with pagination.  I can't seem to get my head around what I might need to do.  I get results for the first run of the query and links to other pages.  But I need to somehow capture my variables so that I can run the query again for the other links for the results.  I believe my problem lies with either the way I have my query set up or perhaps there is another way to set up the 'links' in the pagination.

Here's the code:

browse.php
[code]      <h1>Pick Your Search Options:</h1>
      <font face="Verdana, Arial, Helvetica, sans-serif" color="#30302f"><b>Browse
      by Author</b></font> <br>
      <br>
      <form method="post" action="../php/browseresults.php">
        <div align="left">
          <select name="author">
            <option selected>Select</option>
            <option value="a-f">A-F</option>
            <option value="g-l">G-L</option>
            <option value="m-r">M-R</option>
            <option value="s-z">S-Z</option>
          </select>
          <input name="Search" type="submit" id="Search" value="Search">
        </div>
      </form></p>
      <hr>
      <p><font face="Verdana, Arial, Helvetica, sans-serif" color="#30302f"><b>Browse
        by Title</b></font> <br>
        <br>
      <form method="post" action="../php/browseresults.php">
        <div align="left">
          <select name="title">
            <option selected>Select</option>
            <option value="a-f">A-F</option>
            <option value="g-l">G-L</option>
            <option value="m-r">M-R</option>
            <option value="s-z">S-Z</option>
          </select>
          <input name="Search" type="submit" id="Search" value="Search">
        </div>
      </form></p>
      <hr>
      <p><font face="Verdana, Arial, Helvetica, sans-serif" color="#30302f"><b>Browse
        by Topic</b></font> <br>
        <br>
      <form method="post" action="../php/browseresults.php">
        <div align="left">
          <select name="topic">
            <option selected>Select</option>
            <option value="Anthology">Anthology</option>
            <option value="Art">Art</option>
            <option value="Biography">Biography</option>
            <option value="Children">Children</option>
            <option value="Classics">Classics</option>
            <option value="Computer">Computer</option>
            <option value="Cooking">Cooking</option>
            <option value="Fiction">Fiction</option>
            <option value="Health & Diet">Health & Diet</option>
            <option value="History">History</option>
            <option value="Humor">Humor</option>
            <option value="Inspirational">Inspirational</option>
            <option value="Job Search">Job Search</option>
            <option value="Literary Criticism">Literary Criticism</option>
            <option value="Mystery">Mystery</option>
[/code]
I abreviated the remaining dropdown option list (you get the idea).

Heres my php code:

browseresults_code.php
[code]<?php

  $start=$_GET['start'];
  $end=$_GET['end'];
  $topic=$HTTP_POST_VARS['topic'];
  $title=$HTTP_POST_VARS['title'];
  $author=$HTTP_POST_VARS['author'];

if ($topic) {
$query="select * from jandj_jandj.books where theme = '".$topic."' and referenceNum=0";
}

if ($title) {
if ($title == "a-f")
$query="select * from jandj_jandj.books where (title between 'a' and 'f') and referenceNum=0";
if ($title == "g-l")
$query="select * from jandj_jandj.books where (title between 'g' and 'l') and referenceNum=0";
if ($title == "m-r")
$query="select * from jandj_jandj.books where (title between 'm' and 'r') and referenceNum=0";
if ($title == "s-z")
$query="select * from jandj_jandj.books where (title between 's' and 'z') and referenceNum=0";

}

if ($author) {
if ($author == "a-f")
$query="select * from jandj_jandj.books where (author between 'a' and 'f') and referenceNum=0";
if ($author == "g-l")
$query="select * from jandj_jandj.books where (author between 'g' and 'l') and referenceNum=0";
if ($author == "m-r")
$query="select * from jandj_jandj.books where (author between 'm' and 'r') and referenceNum=0";
if ($author == "s-z")
$query="select * from jandj_jandj.books where (author between 's' and 'z') and referenceNum=0";

}

$database=mysql_pconnect('localhost','jandj_root');
mysql_select_db('books');

// query defined above
$result=mysql_query($query);
echo 'result = '.$result;

// Figure out the total number of results in DB:
$total_results = mysql_num_rows($result);

// Define the number of results per page
$max_results = 10;

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// If current page number, use it
// if not, set one!

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Build Page Number Hyperlinks
echo '<br><center><font color="#000000" size="1" face="Geneva, Arial, Helvetica, sans-serif"><b>Select a Page</b></font><br><br>';

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo '<a href="../php/browseresults.php?keywords='.$searchwords.'&page='.$prev.'">&laquo;&laquo; Previous</a> ';
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo '<font color="#000000" face="Geneva, Arial, Helvetica, sans-serif">[ '.$i.' ]</font> ';
        } else {
            echo '<a href="../php/browseresults.php?keywords='.$searchwords.'&page='.$i.'">['.$i.']</a> ';
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo '<a href="../php/browseresults.php?keywords='.$searchwords.'&page='.$next.'">Next &raquo;&raquo;</a>';
}
echo "</center><br><hr>";

// find the starting record number
$start_record = (($max_results * $page) - $max_results);

// now we modify our original sql statement to return only the results we are displaying
$query .= ' limit '.$start_record.', '.$max_results;

$result=mysql_query($query);
$rowcount=mysql_num_rows($result);

if ($rowcount != '') {
for ($i=0; $i<$rowcount;$i++)   
{
$column=mysql_fetch_array($result);
$image=$column[7];
$title=$column[1];
$author=$column[3];
$commentary=$column[5];
$id=$column[0];
// echo 'Commentary = '.$commentary;

echo '<p>';
echo '<img src="../images_books/'.$image.'" width="94" height="138" align="left">';
echo '<font color="#7b8049" face="Geneva, Arial, Helvetica, sans-serif"><b>';
echo $title;
echo '</b></font><br>
<b><font color="#000000" size="1" face="Geneva, Arial, Helvetica, sans-serif">
by '.$author.'
  </font></b>
</p>
<p><font color="#000000" size="1" face="Geneva, Arial, Helvetica, sans-serif">'.$commentary.'</font></p>
<p>
<a href="../php/moreinfo.php?id='.$id.'">More Info</a>
&nbsp;&nbsp;
<a href="../php/addtocart.php?id='.$id.'">Add to Cart</a>
</p>
<br><hr>';
}
} else {
echo '<font color="#000000" size="1" face="Geneva, Arial, Helvetica, sans-serif"><b>';
echo "We're sorry.  There are no books in the database that match that specific criteria. <br><br>  ";
echo 'Please return to the <a href="browse.php">Browse page</a> and selected another criteria.'; 
echo '</b></font><br><hr>';

}
?>[/code]

The way the dropdowns should work is as a choice of search method.  Therefore, I either need to scrap the way my query is set up...or somehow I need to be able to select the appropriate 'variable' so that the pagination will run the query again when the next page 'link' is clicked.  Right now, as I said before, I get my pagination but the links to the other pages don't work.  Also, I am aware that the current variables in the 'pagination' portion of my above code are incorrect.  I've tried many things and I'm just not sure how to go about this.

All and any help would be GREATLY appreciated!!

Cheers,


M
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.