如何检查mysql查询中的字段条件

时间:2016-04-15 09:48:32

标签: php mysql

我有一个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_statusWHERE)支票?

1 个答案:

答案 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_*