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 . Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/ Share on other sites More sharing options...
Guest 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"; } 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? 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"; Link to comment https://forums.phpfreaks.com/topic/252453-php-query-help/#findComment-1294347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.