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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -