gpt4 book ai didi

php - 带有非空变量的 where 子句

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

下面的一些变量(us1 或 sp1..)可能有空值(客户有可能不填写相应的 TextView )。我如何使用“not null”变量来语法“where”子句;例如,当 us1 不为空且 sp1 为空时,“where”子句必须为:“where customer.username1 = 'us1'”提前致谢

$us1 = $_POST['username1'];
$sp1 = $_POST['startPoli1'];

SELECT `username1`,`startPoli1`, `finalPoli1`,`weight1` ,`phone1`
FROM customer ,registration1
where customer.startPoli1 = 'sp1' and customer.username1 = 'us1'

最佳答案

这样写条件:

WHERE ('sp1' IS NULL OR customer.startPoli1 = 'sp1')
AND ('us1' IS NULL OR customer.username1 = 'us1')

关于php - 带有非空变量的 where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26570897/

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