Mesh3L Posted April 27, 2011 Share Posted April 27, 2011 Hello,I have a form that has some options for the user (e.x, color,size and price). For every one the user can select a specific value from a menu OR select ALL (e.x: COLOR : ALL,RED,BLUE,BLACK).Now, I have one SELECT query that looks similar to (SELECT * FROM TABLE WHERE COLOR='$COLOR' AND SIZE='$SIZE' AND PRICE='$PRICE':)BUT, if for one of the options, the user selects the value "ALL". This will effect the query and return null.Is there some thing in the query that i can change to ignore that specific option if the value is ALL ?The only in hand solution i can think of now is to make an IF statements for every scenario with a separate query for each one. But this will take for ever as i have more options that mentioned.UPDATE :I found one solution by replacing ALL with '%' and than use LIKE '%' instead of the equal sign.If anyone has another suggestion please post it.Thank you Link to comment Share on other sites More sharing options...
birbal Posted April 27, 2011 Share Posted April 27, 2011 You can prepare the sql in php. You can remove the condition of color(eg COLOR='$COLOR') if user select 'all' ...else add the where clause. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.