tekrscom Posted August 14, 2009 Share Posted August 14, 2009 I'm not even sure if this is possible or not, but somehow I have to get an IF statement inside of a query or find an alternative... So, here's my query... //Just for reference $query=""; if ($_SESSION['SearchParameter'][4]==1){$query=$query."Old=1, ";} if ($_SESSION['SearchParameter'][5]==1){$query=$query."Fat=1, ";} if ($_SESSION['SearchParameter'][11]==1){$query=$query."Bukkake=1, ";} if ($_SESSION['SearchParameter'][12]==1){$query=$query."Bondage=1, ";} if ($_SESSION['SearchParameter'][13]==1){$query=$query."Cuckold=1, ";} if ($_SESSION['SearchParameter'][22]==1){$query=$query."Gay=1, ";} if ($_SESSION['SearchParameter'][23]==1){$query=$query."BiSexual=1, ";} if ($_SESSION['SearchParameter'][24]==0){$TempGender='Either';} if ($_SESSION['SearchParameter'][24]==1){$TempGender='Male';} if ($_SESSION['SearchParameter'][24]==2){$TempGender='Female';} if ($_SESSION['SearchParameter'][25]==0){$TempPrivacySetting="";} if ($_SESSION['SearchParameter'][25]==1){$TempPrivacySetting=" AND Users.PrivacySetting = 'Public'";} $query = substr_replace($query," ",-2); //The query $sub_query = "SELECT Interests.*, Users.* ". "FROM Interests RIGHT JOIN Users ". "ON Interests.UserID = Users.UserID WHERE Users.Gender = '$TempGender' $TempPrivacySetting AND $query ORDER BY LogOnDate DESC"; Now what I'm trying to add to this query here is to eliminate results where the Users.Yahoo and Users.MSN are both blank. Quote Link to comment https://forums.phpfreaks.com/topic/170324-solved-query-with-some-type-of-if-statement/ Share on other sites More sharing options...
therealwesfoster Posted August 14, 2009 Share Posted August 14, 2009 In the WHERE add: AND (Users.Yahoo!='' AND Users.MSN!='') Wes Quote Link to comment https://forums.phpfreaks.com/topic/170324-solved-query-with-some-type-of-if-statement/#findComment-898529 Share on other sites More sharing options...
tekrscom Posted August 15, 2009 Author Share Posted August 15, 2009 In the WHERE add: AND (Users.Yahoo!='' AND Users.MSN!='') Wes Yeah, don't know why that evaded me, that sounds perfectly logical... but it doesn't work... It only produces a result if the User has both a Yahoo and an MSN... Not if they are missing both... Here's what I did with the query... $sub_query = "SELECT Interests.*, Users.* ". "FROM Interests RIGHT JOIN Users ". "ON Interests.UserID = Users.UserID WHERE Users.Gender = '$TempGender' $TempPrivacySetting AND (Users.Yahoo!='' AND Users.MSN!='') AND $query ORDER BY LogOnDate DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/170324-solved-query-with-some-type-of-if-statement/#findComment-898544 Share on other sites More sharing options...
roopurt18 Posted August 15, 2009 Share Posted August 15, 2009 AND NOT (Users.Yahoo='' AND Users.MSN='') Quote Link to comment https://forums.phpfreaks.com/topic/170324-solved-query-with-some-type-of-if-statement/#findComment-898558 Share on other sites More sharing options...
tekrscom Posted August 15, 2009 Author Share Posted August 15, 2009 AND NOT (Users.Yahoo='' AND Users.MSN='') Yep, that did it... Thank you both very much for your assistance... Quote Link to comment https://forums.phpfreaks.com/topic/170324-solved-query-with-some-type-of-if-statement/#findComment-898560 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.