Tenaciousmug Posted May 14, 2011 Share Posted May 14, 2011 Ok I'm trying to select the pet with the current eggid in the url. That part works fine, but when I try to select more than one color, it gets all messed up. Because I don't know how to do it and I can't find it on the internet anywhere. $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR 'green' OR 'yellow' OR 'red'"; Does anyone know how to do that? Because whenever I put this: $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR color='yellow' OR color='green' OR color='red'"; It gets all messed up. It selects ALL the colors even if the eggid isn't the current eggid. So it displays the colors of all the pets that have those colors.. :/ EDIT: OR is this the only way I can do it: $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR eggid='".$_GET['eggid']."' AND color='green' OR eggid='".$_GET['eggid']."' AND color='yellow' OR eggid='".$_GET['eggid']."' AND color='red'"; Quote Link to comment https://forums.phpfreaks.com/topic/236376-selecting-multiple-values-from-a-field/ Share on other sites More sharing options...
markjoe Posted May 14, 2011 Share Posted May 14, 2011 the OR clauses are overriding your eggid. $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND (color='blue' OR color='yellow' OR color='green' OR color='red')"; you need to group your conditions in an sql 'where' clause just the same as in an 'if' conditional. Quote Link to comment https://forums.phpfreaks.com/topic/236376-selecting-multiple-values-from-a-field/#findComment-1215269 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.