#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    12
    Rep Power
    0
    I'd really appreciate responses on how to do this:

    I'm trying to select records based on multiple critera.

    $test is a variable that comes in from a form.

    $query2 = "SELECT * FROM trovemain WHERE (cata LIKE '%$test%')";

    This is selecting anything that has $test anywhere in the field "cata".

    Two questions:

    1. will this pick up fields that start or end with $test?

    2. How can I do some logical operators like AND and OR.

    I'd like to use not just $test, but about 10-15 variables and select out records that have variableA AND variableB AND variableC OR variableD

    I can't figure out how to do this...

    your help is appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    1. will this pick up fields that start or end with $test?

    >> should do both

    2. How can I do some logical operators like AND and OR.

    <?
    $searchlist=array("cat", "dog", "mouse");

    $query="SELECT * from trovemain WHERE ";
    for($i=0;$i<count($searchlist); $i++)
    $query.="cata LIKE '%$searchlist[$i]%' OR ";
    $query=substr($query, 0 -3); // strip off last 'OR '
    $query.=" order by some_column";

    //run the query
    ?>

    You can make the $searchlist array an array of variables from the form.

    You could also include a radio button saying "Search by ALL terms" (AND) or "Search by ANY term" (OR) - this will give you the ability to choose AND or OR for your query syntax.

Similar Threads

  1. How to output multiple paragraphs from mysql
    By mrsmile25 in forum PHP Development
    Replies: 2
    Last Post: February 13th, 2004, 03:53 PM
  2. MySQL multiple virtual site problem
    By kss in forum MySQL Help
    Replies: 0
    Last Post: February 12th, 2004, 12:22 PM
  3. Replies: 2
    Last Post: February 12th, 2004, 07:29 AM
  4. Prevent Mysql from multiple storage
    By pjapen in forum PHP Development
    Replies: 1
    Last Post: February 11th, 2004, 08:53 AM
  5. Build HTML tables with multiple mySQL queries
    By SailFan in forum PHP Development
    Replies: 5
    Last Post: January 19th, 2004, 11:25 AM

IMN logo majestic logo threadwatch logo seochat tools logo