tj71587 Posted October 11, 2007 Share Posted October 11, 2007 I've been working jsp lately and there is a tag that you can place inside the query for an if statement. Obviously there is no tag in php, but is there any way to place an if statement inside the query? Quote Link to comment https://forums.phpfreaks.com/topic/72832-solved-if-inside-query/ Share on other sites More sharing options...
Aureole Posted October 11, 2007 Share Posted October 11, 2007 Not that I know of I think you have to do it like... <?php if(condition 1) { // Query 1 } elseif(condition 2) { // Query 2 } // etc... ?> Quote Link to comment https://forums.phpfreaks.com/topic/72832-solved-if-inside-query/#findComment-367294 Share on other sites More sharing options...
tj71587 Posted October 11, 2007 Author Share Posted October 11, 2007 Yeah thanks, thats what I have been using. I was thinking in terms of SELECT * FROM table WHERE 1=1 if(conditon) { AND .... } if(conditon) { AND .... } if(conditon) { AND .... } But I doubt thats an option, thanks though. Quote Link to comment https://forums.phpfreaks.com/topic/72832-solved-if-inside-query/#findComment-367309 Share on other sites More sharing options...
pocobueno1388 Posted October 11, 2007 Share Posted October 11, 2007 You can keep adding to the query like this: <?php $query = "SELECT * FROM tablem WHERE 1=1"; if(conditon){ $query .= " AND blah='$blah'" } if(conditon){ $query .= " AND whatever='$whatever'" } ?> Is that what your trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/72832-solved-if-inside-query/#findComment-367311 Share on other sites More sharing options...
tj71587 Posted October 11, 2007 Author Share Posted October 11, 2007 Exactly it, thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/72832-solved-if-inside-query/#findComment-367317 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.