How to get field names of mysql table in codeigniter? How to get field names of mysql table in codeigniter? sql sql

How to get field names of mysql table in codeigniter?


using database library write this code to list all fields:

$this->db->list_fields('table')

take a look here: https://codeigniter.com/userguide3/database/results.html#CI_DB_result::list_fields


Some Times this may helpful

$fields = $this->db->field_data('table_name');foreach ($fields as $field){   echo $field->name;   echo $field->type;   echo $field->max_length;   echo $field->primary_key;}


What you did is to get the datas from the table....here your table is user so

in your model function do this...

function get_field(){$result = $this->db->list_fields('user');foreach($result as $field){$data[] = $field;return $data;}}

in your controller do this

function get_field(){$data['field'] = $this->model_name->get_field();$this->load->view('view_name',$data);}

in your view do this

foreach($field as $f){echo $f."<br>"; //this will echo all your fields}

hope this will help you