gpt4 book ai didi

php - codeigniter 中的嵌套查询

转载 作者:行者123 更新时间:2023-11-29 06:38:33 25 4
gpt4 key购买 nike

有问题

$this->db->where("Mark_ID,(SELECT Mark_ID FROM mark WHERE Course_ID=$Course_ID && Matric_No=$Matric_No)");

在我的模型中?有什么建议吗?谢谢。

 function update_record($Course_ID,$Matric_No)
{
if($Course_ID && $Matric_No != NULL)
{
$data = array(
//'Course_ID' => $this->input->post('Course_ID'),
'Matric_No' => $this->input->post('Matric_No'),
'Student_Name' => $this->input->post('Student_Name'),
'Result_Mark_1' => $this->input->post('Result_Mark_1'),
'Result_Mark_2' => $this->input->post('Result_Mark_2'),
'Result_Mark_3' => $this->input->post('Result_Mark_3'),
'Result_Mark_4' => $this->input->post('Result_Mark_4'),
'Result_Mark_5' => $this->input->post('Result_Mark_5')

);

$this->db->where("Mark_ID,(SELECT Mark_ID FROM mark WHERE Course_ID=$Course_ID && Matric_No=$Matric_No)");

$this->db->update('mark', $data);
}
}

最佳答案

你需要使用IN()子句

$subquery="SELECT Mark_ID FROM mark WHERE Course_ID=$Course_ID && Matric_No=$Matric_No";
$this->db->where("Mark_ID IN($subquery)",null,FALSE);

但是你使用来自同一个表的子查询来更新你将面临错误

you can't specify target table in update query

为此,您需要为您的子查询提供新的别名,例如

$subquery="SELECT t.Mark_ID FROM(
SELECT Mark_ID
FROM mark
WHERE Course_ID=$Course_ID && Matric_No=$Matric_No
) t ";

$this->db->where("Mark_ID IN($subquery)",null,FALSE);

关于php - codeigniter 中的嵌套查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22959729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com