Jump to content

selecting with LIKE and %'s


.josh

Recommended Posts

I have a form where I have 3 optional fields to fill out that builds a query string, and the end result could look like any one of the following, depending on whether any/all fields were filled out:

 

Returns everything....

a) .. like '%%' // everything

b) .. like '$x%%' // starting with $x

c) .. like '$x%$y%' // starting with $x, containing $y

d) .. like '$x%$y%$z' // starting with $x, containing $y, ending with $z

e) .. like '%$y%$z' // containing $y, ending with $z

f) .. like '%%$z' // ending with $z

g) .. like '%$y%' // containing $y

h) .. like '$x%$z' // starting with $x, ending with $z

 

Now the results seem to always come back the way I expect them to.  But I'm just curious about patterns a,b and f.  They seem to work...but why? I thought I would have to use extra conditions to make the string only

 

a) not include a like clause at all (so as to return everything)

b) show .. like '$x%'

f) show .. like '%z'

 

but apparently having double %'s seems to work. So...why? The manual says

 

Character Description

% Matches any number of characters, even zero characters

 

So I'm interpreting that as 0 + 0 still equals 0 in the end, no harm no foul.  Is my interpretation correct?

Link to comment
https://forums.phpfreaks.com/topic/113172-selecting-with-like-and-s/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.