Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.