gpt4 book ai didi

php - zend 框架 2.2 中的嵌套 where 子句

转载 作者:可可西里 更新时间:2023-11-01 07:20:19 25 4
gpt4 key购买 nike

我需要这样的查询

SELECT tbl_leads . * , tbl_lead_category.vLeadCategoryName AS vLeadCategoryName, tbl_lead_category.vLeadCategoryIcon AS vLeadCategoryIcon, Concat( vFirst, ' ', vLast ) AS vFirst
FROM tbl_leads
LEFT JOIN tbl_lead_category ON tbl_lead_category.iLeadCategoryID = tbl_leads.iLeadCategoryID
LEFT JOIN tbl_user ON tbl_user.iUserID = tbl_leads.iUserID
WHERE (
tbl_leads.eDeleted = '0'
)
AND (
tbl_leads.iUserID = '1'
)
AND (
vCompanyName LIKE '%t%'
OR vCompanyUrl LIKE '%t%'
OR vPersonName LIKE '%t%'
OR vDesignationName LIKE '%t%'
OR vSkypeID LIKE '%t%'
OR vEmailID LIKE '%t%'
OR vPhoneNumber LIKE '%t%')

我的代码是这样的:

public function fetchAll($data, $aColumns, $iUserID = "")
{
$select = $this->tableGateway->getSql()->select();
$select->columns(array('*'));
$select->join('tbl_lead_category', 'tbl_lead_category.iLeadCategoryID = tbl_leads.iLeadCategoryID', array('vLeadCategoryName', 'vLeadCategoryIcon'), "LEFT")
->join('tbl_user', 'tbl_user.iUserID = tbl_leads.iUserID',array("vFirst"=>new \Zend\Db\Sql\Predicate\Expression("Concat(vFirst,' ',vLast)")),"LEFT");

$where = new \Zend\Db\Sql\Where();
$where->NEST->equalTo('tbl_leads.eDeleted','0')->UNNEST;

if(isset($iUserID) && $iUserID != "")
$where->AND->NEST->equalTo ('tbl_leads.iUserID', $iUserID)->UNNEST;

// start for searching
if (isset($data['sSearch']) && $data['sSearch'] != "") {
for ($i = 0; $i < count($aColumns) - 1; $i++) {
$where->OR->like($aColumns[$i], "%" . $data['sSearch'] . "%");
}
}

/*i have tried this, but its giving error: not nested*****
if (isset($data['sSearch']) && $data['sSearch'] != "") {
$where->AND->NEST;
for ($i = 0; $i < count($aColumns) - 1; $i++) {
$where->OR->like($aColumns[$i], "%" . $data['sSearch'] . "%");
// how can i get parentheses to my where which i am searching
}
$where->UNNEST;
} ***************/
$select->where($where);
var_dump($select->getSqlString());
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}

如果我使用 nest 和 unnest 不能通过使用 for 循环和 if 语句创建它,如果我有这样的自定义查询,我该如何进行查询,没有括号,我的查询就没有意义。

最佳答案

我觉得下面的更好。 NEST 将打开括号 UNNEST 将关闭括号

$where = new Sql\Where();
$where->NEST//start braket
->equalTo('col','someVal')
->OR
->equalTo('col','secondVal')
->UNNEST //close bracet

关于php - zend 框架 2.2 中的嵌套 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21773934/

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