#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    6
    Rep Power
    0
    Hi sorry about the length of this but here goes! This page works fine on it's own if i define the city i'm searching for but when i change it to pick up an entry from another page using a drop down box it only works for the first page, but doesn't pick up the selected city for the rest of the pages. I hope that makes sense
    Here's the page:

    <?
    include("mydb.php3");


    // If $offset is set below zero (invalid) or empty, set to zero
    if (empty($offset) &#0124; &#0124; $offset < 0) {
    $offset=0;
    }

    // Connect to database
    mysql_connect("$hostname") OR DIE("Unable to connect to database");
    mysql_select_db("$dbName") or die( "Unable to select database");


    // Set $limit. $limit = Max number of results per 'page'
    // Set $totalrows = total number of rows that unlimited query would return
    // (total number of records to display across all pages)
    $limit = 5;
    $numresults = mysql_query("SELECT * FROM table1 WHERE (city = 'aberdeen')");
    $totalrows = mysql_num_rows($numresults);

    // Set $begin and $end to record range of the current page
    $begin =($offset+1);
    $end = ($begin+($limit-1));
    if ($end > $totalrows) {
    $end = $totalrows;
    }

    // Display result information.
    echo "There are <b>$totalrows</b> results.<br>n";
    echo "Now showing results <b>$begin</b> to <b>$end<b/>.<br><br>n";

    // Now retrieve records for current page
    $query = "SELECT * FROM table1 WHERE (city = 'aberdeen') LIMIT $offset, $limit";
    $result = mysql_query($query);

    while($data = mysql_fetch_array($result)) {
    // Display these records as you like
    print ($data["name"]);
    print "<br>";
    }

    // Begin Prev/Next Links

    // Don't display PREV link if on first page
    if ($offset!=0) {
    $prevoffset=$offset-$limit;
    echo "<a href="$PHP_SELF?offset=$prevoffset" ".
    "onMouseOver="window.status='Previous $limit Results'; return true";>PREV $limit</a> &nbsp; n";
    }

    // Calculate total number of pages in result
    $pages = intval($totalrows/$limit);

    // $pages now contains total number of pages needed unless there is a remainder from division
    if ($totalrows%$limit) {
    // has remainder so add one page
    $pages++;
    }

    // Now loop through the pages to create numbered links
    // ex. 1 2 3 4 5 NEXT
    for ($i=1;$i<=$pages;$i++) {
    // Check if on current page
    if (($offset/$limit) == ($i-1)) {
    // $i is equal to current page, so don't display a link
    echo "$i &nbsp; ";
    } else {
    // $i is NOT the current page, so display a link to page $i
    $newoffset=$limit*($i-1);
    echo "<a href="$PHP_SELF?offset=$newoffset" ".
    "onMouseOver="window.status='Page $i'; return true";>$i</a> &nbsp; n";
    }
    }

    // Check to see if current page is last page
    if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
    // Not on the last page yet, so display a NEXT Link
    $newoffset=$offset+$limit;
    echo "<a href="$PHP_SELF?offset=$newoffset" ".
    "onMouseOver="window.status='Next $limit Results'; return true";>NEXT $limit</a><p>n";
    }

    ?>
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You need to pass the name of the city to the next page. If the form uses name=city in the input element for example, you need to add:

    &city=$city

    at the end of the <a href urls that you are using to build the links with.

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    6
    Rep Power
    0
    Thanks!!! It worked a dream!!! I might be forced to marry you!!!!!!
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    awwwwww, couldn't we just live together for awhile first....

Similar Threads

  1. But how do I exicute it in php to show the results?
    By Paul Knapp in forum PHP Development
    Replies: 6
    Last Post: February 10th, 2004, 11:02 AM
  2. next page for results / overflow result pages
    By virtualdub in forum PHP Development
    Replies: 3
    Last Post: February 5th, 2004, 04:15 PM
  3. getting results from a db inside php
    By gallafrax in forum PHP Development
    Replies: 1
    Last Post: February 4th, 2004, 12:53 PM
  4. Help using a database and php to update a scores page.
    By deathsythe in forum PHP Development
    Replies: 0
    Last Post: February 2nd, 2004, 02:48 PM
  5. Replies: 4
    Last Post: January 28th, 2004, 08:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo