gpt4 book ai didi

php - 我想在这种情况下在哪里有一个?

转载 作者:行者123 更新时间:2023-11-30 00:34:03 25 4
gpt4 key购买 nike

我的 MySQL 中有这个问题,我有 3 个组合框,我想获取它们的值,以便我可以为它们创建一个过滤器。我想要 1 where 这些代码,所以任何人都可以帮助我。 TIA

if($this->input->get('name')) 
$name = $this->input->get('name');
else
$name = "";
$namecondition = "";
if(strlen($name) > 0)
$namecondition .= "WHERE E.`nameid` = '$name'";

if($this->input->get('age'))
$age = $this->input->get('age');
else
$age = "";
$namecondition2 = "";
if(strlen($age) > 0)
$namecondition2 .= "WHERE E.`ageid` = '$name'";

if($this->input->get('year'))
$year = $this->input->get('year');
else
$year = "";
$namecondition = "";
if(strlen($year) > 0)
$namecondition3 .= "WHERE E.`yearid` = '$name'";

$sSQL = "SELECT *,COALESCE(E.`id`,0) AS 'eid'
FROM employee AS E
LEFT JOIN name AS B ON E.nameid = B.id
LEFT JOIN age AS C ON E.ageid = C.id
LEFT JOIN year AS J ON E.yearid = J.id
$namecondition
ORDER BY E.lastName ASC";

最佳答案

这是您的解决方案,使用 where 1=1 并附加以 AND 开头的另一个字符串...

if($this->input->get('name')) 
$name = $this->input->get('name');
else
$name = "";
$namecondition = "";
if(strlen($name) > 0)
$namecondition .= " AND E.`nameid` = '$name'";

if($this->input->get('age'))
$age = $this->input->get('age');
else
$age = "";
$namecondition2 = "";
if(strlen($age) > 0)
$namecondition2 .= " AND E.`ageid` = '$name'";

if($this->input->get('year'))
$year = $this->input->get('year');
else
$year = "";
$namecondition = "";
if(strlen($year) > 0)
$namecondition3 .= " AND E.`yearid` = '$name'";

$sSQL = "SELECT *,COALESCE(E.`id`,0) AS 'eid'
FROM employee AS E
LEFT JOIN name AS B ON E.nameid = B.id
LEFT JOIN age AS C ON E.ageid = C.id
LEFT JOIN year AS J ON E.yearid = J.id
where 1 = 1
$namecondition
ORDER BY E.lastName ASC";

关于php - 我想在这种情况下在哪里有一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com