forumnz Posted December 31, 2007 Share Posted December 31, 2007 Is this just done by ending the query mid way without ending with a ) and then executing the if statement then closing with )? Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/83875-solved-using-an-if-statement-within-a-mysql_query/ Share on other sites More sharing options...
corillo181 Posted December 31, 2007 Share Posted December 31, 2007 why would you want to do something like that? how about put your testing if inside a string? $mystring = ($this == $that) ?'hello': ' no hello'; query("select $mystring from ...") Quote Link to comment https://forums.phpfreaks.com/topic/83875-solved-using-an-if-statement-within-a-mysql_query/#findComment-426844 Share on other sites More sharing options...
p2grace Posted December 31, 2007 Share Posted December 31, 2007 I agree with corillo181, it would bad practice to throw an if statement inside of a query. Much better to create an if statement to create a string variable, then put that string variable into the mysql statement. Quote Link to comment https://forums.phpfreaks.com/topic/83875-solved-using-an-if-statement-within-a-mysql_query/#findComment-426845 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.