What does '%search%' do?

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
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

What does '%search%' do?

Post by mhouldridge »

Hi,

Just wondering about one of my queries....

I use '% %' for searching - Why do we use % here?


thanks
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

%'s are used namely in LIKE statements. the %something% means that you are searching for any string that mathes what is in between the %'s.

ie, if you were searching for anything that had hte word ID in it, like state_id, man_id, or cat_id_num, you could do :

Code: Select all

LIKE %id%
or, you could just use %something

Code: Select all

LIKE %id
which would return ONLY the ones that match having the word "id" at the end of it. the above example would only return, state_id and man_id

last, you could throw it at the end to match anything after the string

Code: Select all

LIKE man%
which would return only man_id
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

% is the marker for wildcard, much like searching on Windows or Unix based OS's with *.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Ahhh!

Very interesting, thanks for that!

Much appreciated!
Post Reply