php - How to write mysql query with WHERE 1 in Codeigniter Active record form -
how write following query
select * `table_name` 1 in codeigniter active record form ?
i tried like:
$this->db->select('*'); $this->db->from('table_name'); $this->db->where('1'); but getting following error:
error number: 1054
unknown column '1' in 'where clause'
select * (`table_name`) `1` null i using same method selecting values database. pass columns, condition , table name. problem is, when want data table, give in clause ?
following query section:
function get($fields,$table,$where) { $this->db->select($fields); $this->db->from($table); $this->db->where($where); $q = $this->db->get(); if($q->num_rows() > 0) { foreach($q->result() $row) { $data[] = $row; } return $data; } } following how call function in controller:
$data['details'] = $this->model_name->get("*",prefix."table_name",1); the model here loaded autoload.
change
$this->db->where($where); into
if ($where !== null) { $this->db->where($where); } and
function get($fields,$table,$where) into
function get($fields,$table,$where=null) so can opt not give $where when call get.
Comments
Post a Comment