Page 1 of 1

partial sql search?

Posted: Fri Jan 02, 2009 12:38 am
by CICS Land
Hey, I'm very new to PHP and just started messing with a site that would allow someone to download files from it. On the form they can type in the file name and search through the SQL table for only an exact match. What I want to be able to do is take whatever they type in and bring back any file name with that in it. I don't know of any SQL function that will allow me to do that, but I easily could be wrong on that, so I was thinking maybe I need to use regular expressions? I tried a few things with regular expressions, but I really didn't understand what I was doing with it.

If you need any examples of what I mean, I can try to be more specific. Any help would be greatly appreciated, thanks!

Re: partial sql search?

Posted: Fri Jan 02, 2009 1:15 am
by requinix
Use LIKE:

Code: Select all

SELECT * FROM table WHERE field LIKE "%text%"
% is a wildcard, basically.

Re: partial sql search?

Posted: Fri Jan 02, 2009 8:59 pm
by CICS Land
Ah, that's what I was looking for. Thanks that worked perfect!