【发布时间】:2018-01-10 14:45:59
【问题描述】:
我正在创建一个简单的表单,其中包含 First_name、Last_name、city 等字段。所以对于城市字段,我想显示动态数据。下面是我在 PHP CodeIgniter 中使用的代码。
控制器页面:
public function city()
{
$this->load->model('dropdownM');
$getcity=$this->dropdownM->get_city();
$this->load->view('form1city',$getcity);
}
模型页面:
<?php
class DropdownM extends CI_Model
{
public function get_city()
{
$this->db->select('fname');
$this->db->from('city');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result();
}
}
}
查看页面:
<form action="<?php echo base_url(); ?>index.php/Rec/user" method="post">
<select class="form-control" id="city" name="city">
<option value="">Select </option>
<?php if(count($getcity)):?>
<?php foreach($getcity as $city):?>
<option value=<?php echo $city->c_id;?>><?php echo $village1->C_name;?></option>
<?php endforeach;?>
<?php else:?>
<?php endif;?>
</select>
<center>
<input type="submit" value="Submit" class="btn btn-bricky" id="subbtn"
name="submit1">
</center>
<form>
它没有在下拉列表中显示任何内容。我无法找出问题所在。
【问题讨论】:
标签: php html codeigniter codeigniter-3