Litle help with advanced Search

Discussion in 'PHP' started by Kyriakos, May 12, 2009.

  1. #1
    hi,

    i have a Searching SQL Query:
    $sql=mysql_query("SELECT * FROM products WHERE (code LIKE '%$sr%' OR model LIKE '%$sr%' OR manuf LIKE '%$sr%' OR keywords LIKE '%$sr%') AND status=1");
    PHP:
    I want to search my database by those criteria:

    all of the words
    the exact phrase
    at least one of the words

     
    Kyriakos, May 12, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    your query must be dynamic if your going for advanced search, i mean specified searching..
    this might not work accurately..
     
    bartolay13, May 13, 2009 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    i'm new in PHP. could you tell me the way for this Query?
     
    Kyriakos, May 13, 2009 IP
  4. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #4
    for example there should be some radio button(not necessarily radio button, text boxes, checkboxes, etc...)..
    ie.
    - lastname, firstname

    or add more criterias
    ie.
    - location, city,

    then execute a condition that if one of these criteria is empty or not then form a string.
    i mean, if location is not specified then $string = ''; thus, all criterias that is specified or is not empty
    should be set, ie, if !empty($location) then $string .= 'and location = $location';

    put it all up and it will construct your query
    mysql_query($string);

    you cant get accurate results if your not filtering your query fields.

    hope that this helps.

    PS. beware of sql injections..
     
    bartolay13, May 13, 2009 IP