SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, sorry that we always have the same questions, but this prev/next function is not so easy.
    I have this "search-result" page here. The prev/next function worked fine bevore I added the search criteria to the SELECT syntax. Now I get the first site of the search-result, that works fine, but when I click to the next page, I get the error message "nothing found" ( which is the error message if $numrows = 0
    Please have a look here:

    $limit=5;
    dbConnect ('mydb');

    $numresults = mysql_query("SELECT * FROM events, loc, date $where");
    $numrows = mysql_num_rows($numresults);

    if (empty($offset)) {
    $offset=0;
    }

    if ($numrows=="") {
    echo("<p>Nothing found, sorry</p>");
    exit();
    }

    if (empty($page)) {
    $page = 1;
    }

    $offset = $limit * ($page - 1);

    // Now the real query

    $result = mysql_query("SELECT events.ev_id, events.dc_s, loc.bez, date.date FROM events, loc, date $where LIMIT $offset,$limit ");
    if (!$result) {
    echo("<P>The following error happendBR>".
    "Error: " . mysql_error());
    exit();
    }

    // The function table out is for to output the dates in a table

    table_out ($result);
    ?>

    The variable $where depends on what the user is searching for.
    If I make an echo ("$numrows") , I get real result of number of rows on the first page but 0 on the second page.
    Do you also need to see the second part of the script, where I make the prev/next buttons itself.

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is in $where?

    $numresults = mysql_query("SELECT * FROM events, loc, date $where");

    Also

    if ($numrows=="") {
    echo("<p>Nothing found, sorry</p>");
    exit();
    }

    check for empty string (and do you mean to check for 0 there??)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is $where:

    $where = " where events.ev_id > 0 AND events.loc_id=loc.loc_id AND events.ev_id=date.ev_id ";
    if ($dc_s != "") {
    $where .= " AND dc_s LIKE '%$dc_s%'";
    }
    if ($name != "") {
    $where .= " AND loc.bez='$name'";
    }
    if ($ort != "") {
    $where .= " AND loc.ort LIKE '%$ort%'";
    }
    if ($plz != "") {
    $where .= " AND loc.plz LIKE '$plz%'";
    }
    if ($cat != "0") {
    $where .= " AND events.cat='$cat'";
    }
    if ($dateselect) {
    $where .= " AND date.date='$veranstart'";
    }

    I get $dc_s and $name...from a form. If the form-field is blank, it will not be a part of the WHERE string.
    What do you mean with : "check for empty string (and do you mean to check for 0 there??)"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •