【发布时间】:2020-07-05 15:39:00
【问题描述】:
假设我有这张表和它的行
我希望只得到post_id 和student_id 中的每一个
对于post_id = 1只需要得到这些
> 1. Capital of Australia
>
> 2. Capital of Philippines
>
> 3. What is the color of pineapple
>
> 4. What is the color of mars
对于post_id = 7只需要得到这些
1. What is the law of war? 2. What is the color of tree?
这是我的查询 - 我需要选择学生 ID 以向每个学生显示他们的数据并发布每个学生数据的 ID。
public function results($id){
$this->db->select('*');
$this->db->from('results');
$this->db->where('student_id', $id);
$this->db->where('post_id', $id);
$this->db->group_by('question');
$query = $this->db->get();
return $result = $query->result_array();
}
【问题讨论】:
-
$this->db->where(['student_id' => $id, 'post_id' => $id]); -
student_id和post_id怎么能一样?
-
在这里输入完全符合您期望的查询?如果不在这里添加一些示例数据的表模式。
-
第一次查看时,我觉得student_answer 列保存了真实答案,反之亦然。您应该将问题表标准化为另一个具有真实答案的问题表,并在此处使用 id,因为它在此处复制了很多次。
-
您似乎在问以下查询:“请向我展示给定 student_id 和给定 post_id 的所有问题”。这是一个逻辑上依赖于 2 个参数的查询。你的函数
results只有一个参数。
标签: php mysql codeigniter codeigniter-3