...

View Full Version : Resolved select from table



Feckie
09-05-2009, 11:01 AM
Hi,
Is it possible to have multiple words like "Comedy Action SciFi" in a Table, then select one of the words ie



$result = mysql_query("SELECT * FROM `films` WHERE Extras = 'Comedy' ORDER BY `Title`");


I have tried the above, Is there a like command ?

kbluhm
09-05-2009, 12:26 PM
Yup, and the % sign is considered a wildcard:


// 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`");

SKDevelopment
09-05-2009, 12:29 PM
I have tried the above, Is there a like command ?

Yes, there is LIKE:


$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.

Feckie
09-05-2009, 01:55 PM
Yes, there is LIKE:


$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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum