php - 无法填充第二个下拉列表
问题描述
为什么每次我从“国家/地区”中选择时,它都不会填充该特定国家/地区的州列表。我有两张桌子,一张是国家的,另一张是州的。
private $_table = "tbl_country";
## MY MODEL ##
function get_by_id($id)
{
$query = $this->db->get_where($this->_table, "ID = $id");
$data = $query->row();
$query->free_result();
return $data;
}
function fetchCountry()
{
$this->db->select('Country');
$this->db->from('tbl_country');
$this->db->order_by('Country', "asc");
$get = $this->db->get();
return $get->result_Array();
}
function fetchState($data)
{
$this->db->select('State');
$this->db->from('tbl_state');
$this->db->where($data);
$this->db->order_by('State', "asc");
$get = $this->db->get();
return $get->result_Array();
}
1.这是我的看法php
<div class="form-group">
<label>Country</label>
<?= form_dropdown('Country', [
'' => '--Select Country--',
'United States' => 'United States'
], set_value('Country', @$rs->Country? $rs->Country: ''), 'class="form-control"id="Country"') ?>
<?= form_error('Country') ?>
</div>
<div class="form-group">
<label>State</label>
<select name="State" id="State" class="form-control">
<option value="" selected disabled>--Select State--</option>
</select>
控制器
函数 showCountry() { $result = $this->country_m->fetchCountry(); 回声 json_encode($result);
}function showState() { $data = $this->input->post(); $result = $this->country_m->fetchState($data); echo json_encode($result); }
解决方案
您不会以这种方式获得它。您必须使用 Ajax 功能,因为它们是相关的下拉菜单。
推荐阅读
- flutter - 如何在 Flutter 中从导航栏调用方法
- java - 如何创建自己的 Open ID 连接授权服务器
- kubernetes - 在 k8s1.16 中使用 kubenet 和双栈时,如何配置在另一个节点上 ping cbr0 gw?
- python - 在 Python 中运行代码时避免 Excel 中的弹出窗口
- javascript - 具有 matchMedia 函数 Vue.js 的计算属性
- ios - 如何在 app 和 Bundle 中使用相同的类?
- java - 如何为 Apache POI 访问存储在 Sharepoint 上的 .xlsx 文件(通过身份验证)?
- ios - 如何将自定义标记从服务器添加到谷歌地图?迅速
- python - 如何在不使用排序功能的情况下查找列表中的元素是升序还是降序?
- laravel - PHP 致命错误:在第 100 行的 /home/e/eraser/domains/domain.com/app/Http/Controllers/Auth/RegisterController.php 中找不到类 'App\\User'