gpt4 book ai didi

mysql - 基于选择查询更新查询

转载 作者:行者123 更新时间:2023-11-30 00:45:16 25 4
gpt4 key购买 nike

我确实想将“UPDATE”和“SELECT”写入一个查询中。

我需要检查设置字段。对于此操作,我在 TABLE1 上使用 SELECT 查询,然后如果没有结果,则更新 TABLE2 的另一个字段。例如:

$res = mysqli_query($con , "select sID FROM schedule where (dayID = '{$this->dID}' AND patientID = '')");
$rep = mysqli_fetch_array($res);
if(count($rep) == 0)
mysqli_query($con,"update days set schFilled = 1 where dID = '{$this->dID}'");
else
mysqli_query($con,"update days set schFilled = 0 where dID = '{$this->dID}'");

我想用一个查询来运行它们,事实上我想要这样的东西:(whit CASE 也可以写第二个更新)

update days set schFilled = 0 where( (select sID FROM schedule where (dayID = '{$this->dID}' AND patientID = '') IS NULL) AND (dID = '{$this->dID}'))

最佳答案

像这样使用 mysqli 对象:

 $res = mysqli_query($con , "your select");
if($res->num_rows === 0) {
//no res
}
else {
//else
}

关于mysql - 基于选择查询更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21432732/

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