ctcp Posted December 4, 2011 Share Posted December 4, 2011 <?php $usergender = mysql_query("SELECT * FROM `fb_acc` WHERE `user_id`='{$data->id}'"); $rowuser = mysql_fetch_object($usergender); $xx = $rowuser->gender; $usercountry = strtoupper($autocountry); $Regions = mysql_query("SELECT * FROM `regions` WHERE `active`='1' AND `shortname`='$usercountry'"); $Regs = mysql_fetch_object($Regions); } if(!$Regs) { $site2 = mysql_query("SELECT * FROM facebook a WHERE (a.active= '0' AND `gender`='$xx' AND (SELECT `coins` FROM `users` WHERE `id`=a.user) > a.cpc) AND a.id NOT IN (SELECT `site_id` FROM `liked` WHERE `user_id`='{$data->id}') AND `regionid`=1 ORDER BY a.cpc DESC LIMIT 0, 16"); } else { $site2 = mysql_query("SELECT * FROM facebook a WHERE (a.active= '0' AND `gender`='$xx' AND (SELECT `coins` FROM `users` WHERE `id`=a.user) > a.cpc) AND a.id NOT IN (SELECT `site_id` FROM `liked` WHERE `user_id`='{$data->id}') AND (`regionid`='Regs->id' OR `regionid`='Regs->continent' OR `regionid`=1) ORDER BY a.cpc DESC LIMIT 0, 16"); } $ext = mysql_num_rows($site2); if($ext > 0){ ?> in my database row gender i got 3 options female male all (or both) how can i say if if($xx=all) show both records mela and female . Quote Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/ Share on other sites More sharing options...
Spring Posted December 4, 2011 Share Posted December 4, 2011 Is this what you mean? 1 = male 2 = female 0 = all? if($xx = 0){ $sql = "SELECT * FROM table WHERE gender = 1 AND gender = 2"; } Quote Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/#findComment-1294343 Share on other sites More sharing options...
ctcp Posted December 4, 2011 Author Share Posted December 4, 2011 i need to run new query ? its any another way to do that? Quote Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/#findComment-1294344 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 If the gender is specified as both, just omit it as a parameter in the query string. Most often if you just build the query string dynamically, you don't need to construct multiple query strings just because the WHERE clause parameters change. // assuming you've already validated/sanitized the value of $_POST['gender'] $gender = $_POST['gender'] == 'both' ? '' : "AND gender = '{$_POST['gender']}"; $query = "SELECT field FROM table WHERE a.active = 0 $gender"; Quote Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/#findComment-1294347 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.