Jump to content

php query help


ctcp

Recommended Posts

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.