gpt4 book ai didi

mysql - 将值从数据库获取到组合框的问题

转载 作者:行者123 更新时间:2023-11-30 01:30:00 25 4
gpt4 key购买 nike

这是我的 Controller :

<?PHP
class combobox extends CI_Controller
{

function dynamic_combobox()
{

$this->load->model('combobox_model');
$data['college'] = $this->combobox_model->getcollege();
$this->load->view('header', $data);
$this->load->view('left_menu', $data);
$this->load->view('manage_user', $data);
$this->load->view('footer', $data);
}

}

?>

这是我的模型:

$this->db->get('colleges'); 
$data = array();
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row){ $data[] = $row; }
}
$query->free_result();
return $data;

这是我的观点:

<form action="<?php echo site_url(''); ?>" method="post">
College

<select name="id" id="id" style="width: 350px;">
<option class="droplist">Please select colleges</option>
<?
if (count($college)>0)
{

foreach ($college as $row)
{
echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
}
}
?>

</select>
Courses
<select>
<!--<option>UG</option>
<option>PG</option>-->
</select>
<input class="button" type="button" value="Refresh"/>
</form>

最佳答案

尝试一下是否有效,您的模型:

$rs = $this->db->get('colleges'); 
$data = array();
if ($query->num_rows() > 0) {
$data = $rs->result_array();
}
$query->free_result();
return $data;

您的观点:

if (count($college)>0){
foreach ($college as $row){
echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
}
}

编辑1:

$arr[]    = array('college_id' => '1', 'college_name' => 'Nadar Saraswathi College of Engineering and Technology', 'status' => '1', 'created_by' => '1', 'modified_by' => '1', 'created_date' => '2012-09-30 22:51:25', 'modified_date' => '2012-09-30 22:50:28' );
print_r($arr);
echo "<select>";
foreach ($arr as $row){
echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
}
echo "</select>";

关于mysql - 将值从数据库获取到组合框的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17585931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com