Jump to content

SELECTing multiple values from a field


Tenaciousmug

Recommended Posts

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'";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.