Searching a MySQL database...

Discussion in 'PHP' started by jkashu, May 19, 2008.

  1. #1
    How do I search a MySQL database?

    I can do this:

    SELECT name FROM users WHERE city = 'pittsburgh'

    but how do I search for matches CONTAINING pittsburgh?

    Thanks!
     
    jkashu, May 19, 2008 IP
  2. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    SELECT name FROM users WHERE city LIKE '%pittsburgh%'
    
    Code (markup):
     
    TeraTask, May 19, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    The field must be in fulltext mode for the above to work.

    Peace,
     
    Barti1987, May 19, 2008 IP
  4. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Um, what I wrote will work for CHAR, VARCHAR, and TEXT fields. Full Text index is not necessary.
     
    TeraTask, May 19, 2008 IP