Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    197
    Thanks
    29
    Thanked 0 Times in 0 Posts

    select from table

    Hi,
    Is it possible to have multiple words like "Comedy Action SciFi" in a Table, then select one of the words ie

    Code:
    $result = mysql_query("SELECT * FROM `films` WHERE Extras = 'Comedy' ORDER BY `Title`");
    I have tried the above, Is there a like command ?
    Last edited by Feckie; 09-05-2009 at 01:56 PM.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Yup, and the % sign is considered a wildcard:
    PHP Code:
    // match
    $result mysql_query("SELECT * FROM `films` WHERE Extras LIKE 'Comedy%' ORDER BY `Title`");

    // match
    $result mysql_query("SELECT * FROM `films` WHERE Extras LIKE '%Comedy%' ORDER BY `Title`");

    // no match
    $result mysql_query("SELECT * FROM `films` WHERE Extras LIKE '%Comedy' ORDER BY `Title`"); 
    Last edited by kbluhm; 09-05-2009 at 12:28 PM.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Quote Originally Posted by Feckie View Post
    I have tried the above, Is there a like command ?
    Yes, there is LIKE:
    Code:
    $result = mysql_query("SELECT * FROM `films` WHERE Extras LIKE '%Comedy%' ORDER BY `Title`");
    This would select any row where Extras contains "Comedy" anywhere in the string. If collation is set as case-insensitive, the search will be case insensitive.

  • Users who have thanked SKDevelopment for this post:

    Feckie (09-05-2009)

  • #4
    Regular Coder
    Join Date
    Jan 2009
    Posts
    197
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SKDevelopment View Post
    Yes, there is LIKE:
    Code:
    $result = mysql_query("SELECT * FROM `films` WHERE Extras LIKE '%Comedy%' ORDER BY `Title`");
    This would select any row where Extras contains "Comedy" anywhere in the string. If collation is set as case-insensitive, the search will be case insensitive.
    Xcellent that works perfect


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •