简体   繁体   English

mysql条件忽略where子句

[英]mysql condition to ignore where clause

I am trying to execute a mysql query in joomla where it takes a variable in where clause with the first item in drop-down is please select. 我正在尝试在joomla中执行一个mysql查询,其中在where子句中使用变量,其中下拉列表中的第一个项目请选择。 I can set the value of drop-down to any value. 我可以将下拉值设置为任何值。

myquery is like this: myquery是这样的:

$db = JFactory::getDbo();
$m = $db->getQuery(true);
$m="SELECT group_concat(distinct m.email
SEPARATOR ', ' ) FROM member m, email e 
where m.club_name='{email___club_email}' ";
$db->setQuery($m);
$a = $db->loadresult();
var_dump($a);exit;
return $a;

Now How I should put a clause in this query so that If I select "please select" then the where clause in the statement is ignored or I can get all the records in any other manner in the resultset. 现在我应该如何在此查询中放置一个子句,以便如果我选择“请选择”,则忽略语句中的where子句,或者我可以在结果集中以任何其他方式获取所有记录。

尝试类似where m.club_name LIKE '{email___club_email}'" ,并将”请选择“的value更改为%因为%MySQL的通配符

您可以使用始终为true的内容,例如WHERE 1 = 1 ,这将返回所有记录。

You could set the value of the "please select" option as 0, and then do a simple if: 您可以将“请选择”选项的值设置为0,然后执行以下操作:

$m="SELECT group_concat(distinct m.email SEPARATOR ', ' ) FROM member m, email e"; 

if ($email) {
    $m .= " where m.club_name='{email___club_email}' ";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM