lakeshoretech Posted November 11, 2010 Share Posted November 11, 2010 I would like some advice from someone who already has the quick answer. User uses a form (drop down) to define a variable in their search of the db. PHP/MYSQL Choices are ALL, A, B, C. EXAMPLE1 They choose B. $variable = 'B' SELECT .... WHERE.... x table value = $variable (equals B) All works perfectly. EXAMPLE2 Now if they chose ALL (or don't chose), I have a problem. They choose nothing (which should be ALL records). I need it to go back to having no WHERE portion of the sql command, or a WHERE that pulls all records. They choose nothing. $ variable = 'ALL' SELECT ... WHERE... x table value = $variable (which now equals ALL) I thought % was a wildcard but doesn't work. This seems simple... but eludes me. What should I use for a variable value if there is NO selection or ALL selection???? The WHERE x table value = has to equal SOMETHING, right? Should I be using an IF THEN to zap the line if it equals "all"? Any advice would be helpful! Thanks! Quote Link to comment Share on other sites More sharing options...
btherl Posted November 11, 2010 Share Posted November 11, 2010 WHERE column like '%' will fetch everything. The wildcards only work for "like", not for "=". Quote Link to comment Share on other sites More sharing options...
lakeshoretech Posted November 11, 2010 Author Share Posted November 11, 2010 Awesome. Thank you. Quote Link to comment 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.