partial sql search?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CICS Land
Forum Newbie
Posts: 2
Joined: Fri Jan 02, 2009 12:17 am

partial sql search?

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: partial sql search?

Post by requinix »

Use LIKE:

Code: Select all

SELECT * FROM table WHERE field LIKE "%text%"
% is a wildcard, basically.
CICS Land
Forum Newbie
Posts: 2
Joined: Fri Jan 02, 2009 12:17 am

Re: partial sql search?

Post by CICS Land »

Ah, that's what I was looking for. Thanks that worked perfect!
Post Reply