我的模特名称mymodel.php
.....
function all($table,$order)
{
$this->db->select('*');
$this->db->from($table);
$this->db->order_by($order);
$query = $this->db->get();
if ($query->num_rows() == 0) {
return FALSE;
} else {
return $query->result();
}
} .....
我的控制器名称donate.php
.....
function index()
{
$data = array(
'rekening' => $this->mymodel->all('rekening', 'id_rekening ASC'),
);
$this->load->view('client/donate/index', $data);
} .....
此路径视图中的我的视图/ client / donate / index
<?php foreach ($rekening as $rek): ?>
<option value="<?php echo $rek->id_rekening; ?>" <?php echo set_select('ke_rekening', $rek->id_rekening); ?>><?php echo $rek->bank .' - '. $rek->atas_nama_rekening; ?></option>
<?php endforeach ?>
但为什么不能在选择选项中显示?我使用codeigniter 3, Show image
答案 0 :(得分:0)
我认为你必须在模态中传递这样的值。
function all($table,$order)
{
$this->db->select('*');
$this->db->from($table);
$this->db->order_by("id_rekening",$order);
$query = $this->db->get();
if ($query->num_rows() == 0) {
return FALSE;
} else {
return $query->result();
}
}
答案 1 :(得分:0)
如果我弄错了你的问题是获得所有列表,或者你想要选择之前选择的那个选项?
以下是为选择框中的<option>
添加值的解决方案。我还添加了如何选择预先选择的值。
In Model:
$query = $this->db->select('*')
->from($table)
->order_by($order)
->get();
$your_result_array = $query->result_array();
return $your_result_array;
In Controller:
$data = $this->mymodel->all($data1,$data2);
$this->load->view('client/donate/index',['data'=>$data]) ;
Inside Your View:
<?php
if(isset($data) && !empty($data)){
foreach ($data as $single_data){
?> <option value="<?= $data['id_rekening] ?>" <?= $your_selected_value_array['your_selected_value'] === $data['id_rekening] ? 'selected':'' ?> > <?= $data['your_other_data_column_name_here] ?> </option> <?php
}
}else {
?><option> data not found </optiop> <?php
}
?>
答案 2 :(得分:0)
controller donate.php
function index()
{
$data = array('rekening' => $this->mymodel->all('rekening', 'id_rekening'));
$this->load->view('client/donate/index', $data);
}
模型donate.php
function all($table,$order)
{
$this->db->select('*');
$this->db->from($table);
$this->db->order_by($order, 'asc');
$query = $this->db->get();
if ($query->num_rows() == 0) {
return FALSE;
} else {
return $query->result();
}
}