Advanced Search

Results 1 to 4 of 4

Thread: search in all tables

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Smile search in all tables

    hi guys me again this is what i have

    PHP Code:
    $result mysql_query("SELECT * FROM table WHERE firstname LIKE '%".$searchterm."%'"); 
    which works just great BUT if i want to seach
    PHP Code:
    $result mysql_query("SELECT * FROM table WHERE lastname LIKE '%".$searchterm."%'"); 
    how so search ALL rows/columns firstname,lastname,username ect

    P.S i'm getting it slowly lol
    Last edited by TwitterRooms; 01-27-2012 at 08:37 PM.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,681
    Thanks
    80
    Thanked 89 Times in 87 Posts

    Default

    It looks like you want to search through multiple columns in one table as opposed to searching through multiple tables, but let me know if I am wrong.

    Try this

    Code:
    SELECT * FROM table WHERE (lcase(concat(firstname, lastname, username)) LIKE '%$searchterm%')
    To choose the lesser of two evils is still to choose evil. My personal site

  3. The Following User Says Thank You to james438 For This Useful Post:

    TwitterRooms (01-27-2012)

  4. #3
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    you are correct THANK YOU

  5. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,681
    Thanks
    80
    Thanked 89 Times in 87 Posts

    Default

    Glad I could help
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •