tableGateway->getAdapter()); $select = $sql->select(); $select...">

How to get "not equal" in Where?

I have something like this:

$sql = new Sql($this->tableGateway->getAdapter()); $select = $sql->select(); $select -> from('mytable') -> join('exp', 'field1_id=field1.id', '*', 'LEFT'); $where = new Where(); $where -> equalTo('field2_id', $field2_id); $select->where($where); $statement = $sql->prepareStatementForSqlObject($select); 

but what if I want to use "not equalTo"? How to do it?

+4
source share
3 answers

You need to use notEqualTo

 $where->notEqualTo('field2_id', $field2_id); 

http://framework.zend.com/apidoc/2.1/classes/Zend.Db.Sql.Predicate.Predicate.html#notEqualTo

+7
source

This is how I use it, most of us can search for such a request, having such clasues in one request.

 return $details = $this->select(function(Select $select) use ($domain, $domainWithoutWWW){ $select->columns(['dealername'=> 'dealer.name']); $select->join('template',"dealer.template_id = template.id", ['template_name' => 'name','template_html' => 'html','template_css' => 'css'], 'left'); $select->where($select->where->notEqualTo('dealer.used_car_dealer_id',1826)); $select->where(array('dealer.parent' => 0)); $select->where(new In('domain', ['abc.com', 'xyz.com', 'lmn.com'])); }); 
+2
source

The easiest way is to write an inline condition:

 $select->where('field1 != 0'); 
0
source

All Articles