bagnallc Posted July 28, 2006 Share Posted July 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15871-where-statement/ Share on other sites More sharing options...
fenway Posted July 28, 2006 Share Posted July 28, 2006 Huh? You don't want to have that in your WHERE clause? I'm confused. Quote Link to comment https://forums.phpfreaks.com/topic/15871-where-statement/#findComment-65231 Share on other sites More sharing options...
bagnallc Posted July 28, 2006 Author Share Posted July 28, 2006 i actually have the answer now. if i put a 1 in it works fine sorry if didnt explain well Quote Link to comment https://forums.phpfreaks.com/topic/15871-where-statement/#findComment-65266 Share on other sites More sharing options...
fenway Posted July 29, 2006 Share Posted July 29, 2006 Oh... I understand... you wanted to be able to add the entire where clause in pieces. I usually use "1=1" as the base piece. Quote Link to comment https://forums.phpfreaks.com/topic/15871-where-statement/#findComment-65518 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.