我们有2个表tb_kriteria
和tb_subkriteria
,我们必须从tb_subkriteria
获取所有记录,其中id_kriteria
的{{1}}与tb_kriteria
相同在id_kriteria
答案 0 :(得分:0)
运行codeigniter联接查询以获取其他结果,请尝试以下代码以获取输出
$this->db->select('tb_subkriteria.*');
$this->db->from('tb_subkriteria');
$this->db->join('tb_kriteria', 'tb_kriteria.id_kriteria = tb_subkriteria.id_kriteria');
$query = $this->db->get();
return $query->result();
答案 1 :(得分:0)
对此查询使用联接
function tb_subkriteria_by_tb_kriteria($id_kriteria){
$this->db->join('tb_kriteria','tb_kriteria.id_kriteria=
tb_subkriteria.id_kriteria');
return $this->db->where('tb_subkriteria.id_kriteria',$id_kriteria)->get('tb_subkriteria)->result_array();
}
答案 2 :(得分:0)
在这里,您需要使用join
和where
来获取数据
function get_subkriteria($id_kriteria){
$id_kriteria = 18;//suppose
$this->db->select('tb_subkriteria.*');
$this->db->from('tb_subkriteria');
$this->db->join('tb_kriteria', 'tb_kriteria.id_kriteria = tb_subkriteria.id_kriteria');
$this->db->where('tb_subkriteria.id_kriteria',$id_kriteria);
$query = $this->db->get();
echo $this->db->last_query();die;//to see your executed query
if($query->num_rows() > 0){
return $query->result();
}else{
return array();
}
}
答案 3 :(得分:0)
对此查询使用内部联接
function getresult($tid){
$query = $this->db->query("select tb_subkriteria.* from tb_subkriteria inner
join tb_kriteria on tb_subkriteria.id_subkriteria=tb_kriteria.id_kriteria);
return $query->result_array();
}