Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: Urgent: problem with search engine

    Hello

    I want to use a search engine based on text files and I found this one:
    http://php.warpedweb.net/

    I want to search with multiples criteria with text box,checkbox and radio button.

    Basically I already have this code:

    function s_search($query) {
    // Searches for query in the index file.
    // Multiple word search originally contributed by Matthew Furister <matt@agtown.com>

    $query = trim(strtolower(c_strip_chars($query)));
    $search_data = @file($GLOBALS[index_file]) or die("<h4 align=\"center\">$GLOBALS[err_no_search_db]</h4>");
    $pages_found = " ";
    foreach ($search_data as $search_page) {
    $page_arr = explode("|", $search_page);
    $found_count = 0;
    $qry_array = split('[, ]+',trim(strtolower($query)));
    foreach ($qry_array as $qry) {
    if (in_array($qry, $page_arr)) {
    ++$found_count;
    $pages_found .= $page_arr[0] . " ";
    }
    }
    if ($found_count == count($qry_array)) $result_arr[] = $page_arr[0];
    }
    return $result_arr;
    }




    with the form here:

    function s_print_search_form($query) {
    // Function to print the search form.
    ?>
    <div align="center"><form method="post">
    <h4>Search for:</h4>
    <input type="text" name="query" value="<?php echo $query ?>">
    <input type="checkbox" name="query" value="Training"> Training<br>

    <br><input type="submit" value="Search">
    </form></div>

    In this example, the last criteria is taken but the first one is not.
    I want to be able to have something like this:
    search.php?query=phil&training

    If you have any idea, I would be interested to hear it.

    thanks.

  2. #2
    Join Date
    Feb 2004
    Location
    Ninth Hell
    Posts
    19
    I think it would be easier if you split the identifiers to search for with a char other than &, because php interprets & as a variable splitter, taking in the example two retrieval arguments, one is query with value phil and one is training with value null. If you want both arguements, separeted, use sth like:

    Code:
    <input type="text" name="query" value="">
    <input type="checkbox" name="extra" value="Training"> Training<br>
    and use the variable $extra.

    Finally to get the url you want, the above has to be:

    Code:
    <input type="text" name="query" value="">
    <input type="checkbox" name="training" value="Training"> Training<br>

Posting Permissions

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