Zend Framework query does not work? -
i have problem "select" statement in zend select.
public function listanswers($sort_field = 'answer_id', $field = null, $value = null, $strict_filter = false, $client_id = null) { //here $value // $value = "abcd : <?\\?>"; $value = $this->getdefaultadapter()->quote("%".$value."%"); if( !empty($field) && !empty($value) && $strict_filter == false){ $select = $this->select()->where(" client_id != -99 ")->where($field . " $value ")->order($sort_field); } }
and error comes , query printed
select `answer`.* `answer` ( client_id != -99 ) , (client_id = '1') , (answer_text '%abcd : <?\\\\?>%' ) order `add_date` desc
record not come appropriate $value
has.
there no need quote values when using select(), select() provide quotes default. when using select() idea use placeholders instead of concatenation because concatenation may not work.
$select->order()
requires string specify query ('answer_id asc'), unless want whatever default is.
you set $field
, $value
null
default, testing !empty()
doesn't make semantic sense.
don't forget have fetch result , return it.
//assuming dbtable model $this->select() valid. public function listanswers($sort_field = 'answer_id', $field = null, $value = null, $strict_filter = false, $client_id = null) { //here $value // $value = "abcd : <?\\?>"; //unless values strange select() provide quotes //$value = $this->getdefaultadapter()->quote("%".$value."%"); //it may initialize select() before loop $select = $this->select(); if( !is_null($field) && !is_null($value) && $strict_filter == false){ $select->where(" client_id != -99 ") //use placeholders when using select() ->where("$field ?" $value) //specify order string ie: answer_id asc ->order($sort_field . 'asc'); } //return result return $this->fetchall($select) }
good luck