MySQL Database LIKE statement help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

MySQL Database LIKE statement help

Post 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!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

do you mean?
WHERE UserAgent = 'Mozilla%' || UserAgent = '%MSIE%' || UserAgent = '%Windows%' etc.
..not sure I completely understand
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply