【发布时间】:2017-06-12 08:13:37
【问题描述】:
我正在 codeigniter 中创建可靠的选择选项。填充第一个选项很容易,但我在显示第二个选项和第三个选项时有点麻烦。需要这方面的帮助
我的数据库包含:
在头表中: h_id,头字段, 副标题表 h_id、sh_id、副标题字段和 积分表 sh_id、points_name 字段
控制器
class Mobile extends App_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper(array('url','language','form'));
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<p class="text-red">', '</p>');
$this->lang->load('auth');
$this->load->model('mobiles_model');
}
function index()
{
if (!$this->data['logged_in'])
{
redirect('auth/login','refresh');
}
$rows = $this->mobiles_model->get_users_devices();
if ($rows)
{
$this->data['devices_list'] = $rows;
}
$this->_render_page('trackall', $this->data);
}
function _render_page($view, $data=null, $render=false)
{
$this->viewdata = (empty($data)) ? $this->data: $data;
$view_html = $this->load->view($view, $this->viewdata, $render);
if (!$render) return $view_html;
}
}
模态
public function get_users_devices()
{
$this->db->select('A.h_id as id,A.head');
$this->db->from($this->table_head.' as A');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
}
return FALSE;
}
查看
<select id="head" name="head" class="form-control input-sm" onchange = "calljavascriptfunction();">
<option value="default">--Select--</option>
<?php if(isset($devices_list))
foreach ($devices_list as $value) { ?>
<option value="<?php echo $value['h_id'] ?>"><?php echo $value['head'] ?></option>
<?php } ?>
</select>
<select id="subhead" name="subhead" class="form-control input-sm">
<option value="default">--Select--</option>
</select>
<select id="points" name="points" class="form-control input-sm">
<option value="default">--Select--</option>
</select>
我必须根据我选择的内容填充另一个。我尝试了几种方法,但都没有奏效。 感谢您的帮助,我真的陷入了困境。
【问题讨论】:
-
我认为您需要在依赖下拉列表中加载数据的完整代码。
-
是的,我认为只是停留在 ajax 调用和 ci
-
stackoverflow.com/questions/27659934/… 检查此问题及其解决方案。
-
已经试过了,谢谢
-
检查我的答案
标签: javascript php codeigniter drop-down-menu