Page 1 of 1

MySQL Database LIKE statement help

Posted: Sun Feb 01, 2004 1:04 pm
by coreycollins
I'm trying to compare a longer statement with a shorter one. The shorter statement is located in my database while the longer one is acquired from the user.

Here is the statement I am trying to do.
їcode]
SELECT * from SearchEngines WHERE 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)' like UserAgent
ї/code]

UserAgent is the info stored in my database. What is stored there is Mozilla, which is the start of the user entered statement. How could I get this to work?

Thank you!

Posted: Mon Feb 02, 2004 10:10 am
by xisle
do you mean?
WHERE UserAgent = 'Mozilla%' || UserAgent = '%MSIE%' || UserAgent = '%Windows%' etc.
..not sure I completely understand

Posted: Mon Feb 02, 2004 12:35 pm
by McGruff
LIKE '$string' will return rows where the column EXACTLY matches $string.

LIKE '%$string&' will return rows where the column CONTAINS $string.

I couldn't say offhand if the user agent string will always be precisely the same format - you might want to search for bits rather than a full string (just add a bunch of OR clauses).

If you've got msql 4.01, full text cols & MATCH (using boolean options) might be another way to go - see manual.