我目前正在做一个系统。在系统中,有一个名为manage resident的模块;如果单例,已婚和有 child (例如名字,中间名和姓氏),管理居民将获得该居民的信息。
我已经完成添加或创建新常驻部分,我现在正在编辑常驻部分。当我点击编辑常驻时,遇到了错误
Column 'id' in where clause is ambiguous
我有 3 个表:居民表、已婚表和 child 表。 Resident ID是married表的外键,Married ID是children表的外键。
我的每个表的数据示例(列主键,外键,名字,中间名,姓氏
Resident -> id, Testing, Testing, Testing
Married -> Married_id, resident_id, Testing, Testing, Testing
Children -> id, married_id, Testing, Testing, Testing
问题:我怎样才能得到选中的居民的 child ?然后在我的 View 中单独显示在我的字段中。
Controller
$id = $this->uri->segment(4);
$get_children = $this->Crud_model->get_children($id);
型号
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();
}
查看
<?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>
最佳答案
每当您使用 where 条件连接表时,您应该在每一列中写入其引用表名。
所以改变
$this->db->where('id',$id);
到
$this->db->where('resident.id',$id);
关于php - where 子句中的列 'id' 对于 3 个表不明确 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47072825/