PHP Search using WHERE, AND, LIKE, OR Query Functions

How to search multiple fields in a database

Search using WHERE, AND, LIKE, OR Query Functions

  1. Looking for an exact match in field1:
    SELECT * FROM table WHERE field1 = ‘$name’
  2. Looking if the field1 contains the search word anywhere using LIKE and both ‘%%’
    SELECT * FROM table WHERE field1 LIKE ‘%$word%’
  3. Looking if the field1 contains the value that begins with our word using LIKE and the last ‘ %’
    SELECT * FROM table WHERE field1 LIKE ‘$word%’
  4. Looking if the field1 contains the value that ends with our word using LIKE and the first ‘% ‘
    SELECT * FROM table WHERE field1 LIKE ‘%$word’
  5. Looking if our search word appears in both fields using AND
    SELECT * FROM table WHERE field1 LIKE ‘%$word%’ AND field2 LIKE ‘%$word%’
  6. Looking if our search word appears in any of the two fields using OR
    SELECT * FROM table WHERE field1 LIKE ‘%$word%’ OR field2 LIKE ‘%$word%’
  7. Looking if our word is in field1 OR in field2 AND field3 using Parentheses
    SELECT * FROM table WHERE field1 LIKE ‘%$word%’ OR (field2 LIKE ‘%$word%’ AND field2 LIK

11 Responses

  1. what??? explain it carefully

  2. SELECT * FROM table WHERE field1 LIKE ‘%$word%’
    this query gives me an error, seems that is not write spelled

  3. anureet

    cant understand thecode

  4. This web must have more information,as the given data not clear the concepts

  5. SELECT * FROM table WHERE field1 LIKE ‘%$word%’
    this query gives me an error, seems that is not write spelled

  6. anureet view this link http://7mliveonline.com/ it will be helpfull for u.
    regards james

  7. waqas umar

    i m also going to check it kaleem. thanks in advance.

  8. Ohana here is an excelent link which will be helpfull to u.
    regars gery

  9. waqas here is an excelent link for date diffrence which will be helpfull to u… http://7mliveonline.com/
    regars gery

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »