I want to know how to list the tables names from a database in a dropdown in CodeIgniter. I tried using $this->db->list_tables() and use it in a model just like when I want to populate dropdown with values from a table.
Controller:
$data['tables'] = $this->model->get_tables();
$this->load->view('view', $data);
View:
<div class="col-md-2">
<label class="col-md-8 control-label" for="tabel">Data</label>
<div class="col-md-12">
<?php $attributes = 'class="form-control" id="tabel"';
echo form_dropdown('tabel', $tables, set_value('tables'), $attributes);?>
</div>
</div>
Model:
function get_tables(){
$result = $this->db->list_tables();
$tablelist = array('- Table Lists -');
foreach($result as $row) {
return $tables = array($tablelist, $row);
}
}
it returns just the first table [analisis] and the value set to 1 in the dropdown [checked it at the inspect element window].
If I changed it to:
foreach($result as $row) {
echo $row;
}
it returns array of tables [analisistable1table2] on top of the webpage.
