Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php zend framework 2.2中的嵌套where子句_Php_Mysql_Zend Framework2 - Fatal编程技术网

Php zend framework 2.2中的嵌套where子句

Php zend framework 2.2中的嵌套where子句,php,mysql,zend-framework2,Php,Mysql,Zend Framework2,我需要这样的询问 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

我需要这样的询问

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;
}
公共函数fetchAll($data,$aColumns,$iUserID=”“)
{
$select=$this->tableGateway->getSql()->select();
$select->columns(数组('*');
$select->join('tbl_lead_category','tbl_lead_category.iLeadCategoryID=tbl_lead.iLeadCategoryID',数组('vLeadCategoryName','vLeadCategoryIcon'),“左”)
->join('tbl_user','tbl_user.iUserID=tbl_leads.iUserID',数组(“vFirst”=>new\Zend\Db\Sql\Predicate\Expression(“Concat(vFirst',,vLast)”),“LEFT”);
$where=new\Zend\Db\Sql\where();
$where->NEST->equalTo('tbl_leads.edeletted','0')->UNNEST;
如果(isset($iUserID)&&$iUserID!=“”)
$where->AND->NEST->equalTo('tbl_leads.iUserID',$iUserID)->UNNEST;
//开始搜索
如果(isset($data['sSearch'])&&$data['sSearch']!=“”){
对于($i=0;$iOR->like($aColumns[$i],“%”,“%”,$data['sSearch']。“%”);
}
}
/*我已经试过了,但是它的错误是:没有嵌套*****
如果(isset($data['sSearch'])&&$data['sSearch']!=“”){
$where->AND->NEST;
对于($i=0;$iOR->like($aColumns[$i],“%”,“%”,$data['sSearch']。“%”);
//我怎样才能得到括号到我正在搜索的位置
}
$where->UNNEST;
} ***************/
$select->where($where);
var_dump($select->getSqlString());
$resultSet=$this->tableGateway->selectWith($select);
返回$resultSet;
}
如果我使用nest和unnest,则不能使用for循环和if语句创建它, 如果我有这样一个自定义查询,如何进行查询,
如果没有括号,我的查询就没有意义。

要添加表达式嵌套,需要使用
谓词::nest()
。这 将是
$where->nest()
)。返回的对象是一个
谓词集
,它将自动嵌套在查询中

然后,您所需要做的就是在其上循环并添加表达式

$where = new \Zend\Db\Sql\Where();

$predicateSet = $where->nest(); // Returns a new 'predicate set'

if (isset($data['sSearch']) && ! empty($data['aSearch'])) {
  for($x = 0; $x < count($aColumns); $x++) {
    if ($x > 0) $predicateSet->or();

    $predicateSet->like($aColumns[$x], $search);
  }
}
$where->unnest();
$where=new\Zend\Db\Sql\where();
$predicateSet=$where->nest();//返回一个新的“谓词集”
如果(isset($data['sSearch'])和&!empty($data['aSearch'])){
对于($x=0;$x<计数($A列);$x++){
如果($x>0)$predicateSet->or();
$predicateSet->like($aColumns[$x],$search);
}
}
$where->unnest();

我认为下面的方法更好。NEST将打开支架,UNNEST将关闭支架

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

我尝试过这个,但它给我的错误不是嵌套在最后一行。