SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    search engine problem

    Trying to add some more functionality to a search page I'm doing. It's for a catalog system that I'm making searchable and it works, but I added it a checkbox to the form that says "match words exactly" or something like that and that's what I'm trying to do but it doesn't seem to work.

    PHP Code:
    if ($_POST['search']) {
     if (
    strlen($_POST['keywords'])>2) {
      
    $error=0;
      if (
    $_POST['exact']=="on"$keyword $_POST['keywords'];
      else 
    $keyword "%" $_POST['keywords'] . "%";
      
    $sqlquery "SELECT id, category, platform, name, manufacturer, description, price FROM catalog WHERE ";
      if (
    $_POST['searchOptions']==1$sqlquery.="name LIKE '$keyword'";
      elseif (
    $_POST['searchOptions']==2$sqlquery.="description LIKE '$keyword'"
      elseif (
    $_POST['searchOptions']==3$sqlquery.="manufacturer LIKE '$keyword'"
      else 
    $sqlquery.="name LIKE '$keyword' OR description LIKE '$keyword' OR manufacturer LIKE '$keyword'"
      
    $sqlquery.=" AND delflag=0";
      
      echo 
    $sqlquery;
      
    $result dbconnect($sqlquery);
      
    $number mysql_numrows($result);
    ///////////////////////////////////////////////////////// 
    I suppose I could totally change the query if $exact is on and change LIKE to =, but that would involve extra coding which I may eventually do, but I would like to know if there is an easier way. Thanks.

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What if you were to do something like this:
    PHP Code:
    if ($_POST['exact']=="on" )
    {
      
    $keyword $_POST['keywords'];
      
    $operator '=';
    }
    else
    {
      
    $keyword "%" $_POST['keywords'] . "%";
      
    $operator 'LIKE';

    Then chage all your "LIKE"s to $operator
    John

  3. #3
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP John
    What if you were to do something like this:
    ...
    Then chage all your "LIKE"s to $operator
    Brilliant!

    Learning something new everyday here
    Lats...


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
  •