Ang*_*gel 1 php mysql codeigniter
我目前正在做一个系统。系统中有一个叫做manage resident的模块;如果居民是单身,已婚和有孩子(例如名字,中间名和姓氏),管理居民将在这里获得居民的信息。
我已经完成了添加或创建新的常驻部分,我现在在编辑常驻部分。当我点击编辑驻留时,我遇到了错误
where 子句中的列“id”不明确
我有 3 张桌子:居民、已婚和孩子。居民ID是已婚的外键,而已婚ID是孩子表的外键。
我的每个表的数据示例(列主键、外键、名字、中间名、姓氏
Resident -> id, Testing, Testing, Testing
Married -> Married_id, resident_id, Testing, Testing, Testing
Children -> id, married_id, Testing, Testing, Testing
Run Code Online (Sandbox Code Playgroud)
问题:我怎样才能得到选定居民的孩子?然后在我的视图中将其单独显示在我的字段中。
控制器
$id = $this->uri->segment(4);
$get_children = $this->Crud_model->get_children($id);
Run Code Online (Sandbox Code Playgroud)
模型
public function get_children($id){
$this->db->select('*');
$this->db->from('resident');
$this->db->where('id',$id);
$this->db->join('married', 'resident.id = married.resident_id');
$this->db->join('children', 'resident.id = children.married_id');
$query = $this->db->get();
return $query->row();
}
Run Code Online (Sandbox Code Playgroud)
看法
<?php $explode = explode(",",$children->first_name); ?>
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" name="child_fname" id="child_fname"><?= $explode?>
</div>
Run Code Online (Sandbox Code Playgroud)
每当你用 where 条件连接表时,你应该用它的引用表名写每一列。
所以改变
$this->db->where('id',$id);
Run Code Online (Sandbox Code Playgroud)
到
$this->db->where('resident.id',$id);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3759 次 |
| 最近记录: |