.josh Posted July 4, 2008 Share Posted July 4, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113172-selecting-with-like-and-s/ Share on other sites More sharing options...
fenway Posted July 4, 2008 Share Posted July 4, 2008 The extra % doesn't do anything, as you've discovered. But I don't think it's "greedy". Quote Link to comment https://forums.phpfreaks.com/topic/113172-selecting-with-like-and-s/#findComment-581456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.