Jump to content

where statement


bagnallc

Recommended Posts

i have variables in my php code which are set or not set dependent upon the users preferences.

as it is unknown which ones will be set, they all have to include an AND command

so for example these could be some variables

$dog1="AND dog.dog_id IN $users_selection1"
$dog2="AND dog.dog_colour $users_selection2"
$dog3="AND dog.dog_height $users_selection3"

i then have a mysql_query which is as follows (i wont bother with all the php code as its irrelevant, but basically it turns the variables into part of the statement if set by user)
at the moment i put in an sql command which effectively selects all

SELECT pets.petnumber, dog.dog_name
FROM pets
JOIN dog ON pets.dog_id=dog.dog_id
WHERE pets.petnumber is not null $dog1 $dog2 $dog3

So if you looked for dogs that are brown the actual sql command would become

SELECT pets.petnumber, dog.dog_name, cat.cat_name
FROM pets
JOIN dog ON pets.dog_id=dog.dog_id
JOIN cat ON pets.cat_id=cat.cat_id
WHERE pets.petnumber is not null AND dog.dog_colour='brown'


what i want is an alternative way to the "pets.petnumber is not null" example in the above, so in other words a way of skipping straight on to the AND parts of the WHERE statement

any ideas?
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.