我有一个MySQL代码:
$sqlstd = mysql_query(
"SELECT cd.cf_did AS id,
cd.cf_companyname AS name,
cd.cf_description AS descp,
cd.cf_payment AS pay,
cd.cf_status AS status,
GROUP_CONCAT(ct.cf_ctname SEPARATOR ', ') AS cranetype
FROM cf_directory cd,
cf_cranetype ct
WHERE FIND_IN_SET(ct.cf_ctid, cd.cf_cranetype)
GROUP BY cd.cf_did,
cd.cf_companyname,
cd.cf_description,
cd.cf_payment,
cd.cf_status
ORDER BY cd.cf_did DESC LIMIT 4",
$con);
我想在此查询中检查2个WHERE
条件:cd.cf_payment='top' AND cd.cf_status='1'
。
我正在使用此代码:
$sqlstd = mysql_query(
"SELECT cd.cf_did AS id,
cd.cf_companyname AS name,
cd.cf_description AS descp,
cd.cf_payment AS pay,
cd.cf_status AS status,
GROUP_CONCAT(ct.cf_ctname SEPARATOR ', ') AS cranetype
FROM cf_directory cd,
cf_cranetype ct
WHERE cd.cf_payment='top',
cd.cf_status='1'
AND FIND_IN_SET(ct.cf_ctid, cd.cf_cranetype)
GROUP By cd.cf_did,
cd.cf_companyname,
cd.cf_description,
cd.cf_payment,
cd.cf_status
ORDER BY cd.cf_did DESC
LIMIT 4",
$con);
但它不起作用。
如何在cf_payment
条件下添加2个字段(cf_status
,WHERE
)支票?
答案 0 :(得分:0)
哪些条件与AND
/ OR
连接,而不是逗号。
更新
WHERE cd.cf_payment='top',cd.cf_status='1'
要:
WHERE cd.cf_payment='top' AND cd.cf_status='1'
注意:请避免使用mysql_*
函数,因为它们已被弃用。使用PDO_*
或mysqli_*
。