我在显示从数据库中检索到的值并使用codeigniter在下拉菜单中显示这些值时遇到了一些问题。代码如下:
控制器:
<?php
class AuthorSignupC extends CI_Controller
{
function index()
{
$this->load->model('AuthorSignupM');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$data['title']= 'All Conferences';
$data['groups'] = $this->AuthorSignupM->ViewAllConf();
$this->load->view('AuthorSignup', $data);
}
}
型号:
<?php
class AuthorSignupM extends CI_Model
{
function ViewAllConf()
{
$this->db->select('ConfLName');
$this->db->from('conference');
//$query = $this->db->query('SELECT ConfLName FROM conference');
$query = $this->db->get();
return $query->result();
}
}
?>
查看:
<select class="form-control">
<?php
foreach($groups as $row)
{
echo '<option value="'.$row->description.'">'.$row->description.'</option>';
}
?>
</select>
答案 0 :(得分:0)
您只选择一列:
$this->db->select('ConfLName');
$this->db->from('conference');
但正在检索&#39;说明&#39;,我猜您的错误报告设置得太低,无法显示错误。
您应该循环confLName
(或使用$this->db->select('description');
)
<select class="form-control">
<?php foreach($groups as $row) : ?>
<option value="<?php echo $row->ConfLName;?>"><?php echo $row->ConfLName;?></option>
<?php endforeach;?>
</select>