返回是或否PHP查询

时间:2013-08-07 02:15:21

标签: php mysql database

我有以下查询:

    $result = query("SELECT IdUser, followingID FROM following WHERE IdUser = '%d' AND followingID = '%d'", $id, $followingID);

我想知道如果结果是YES,我将如何返回,如果关系存在,我将如何根据0和1计数返回?

1 个答案:

答案 0 :(得分:1)

这是一种方式:

select (case when exists (SELECT IdUser, followingID
                          FROM following
                          WHERE IdUser = '%d' AND followingID = '%d'
                         )
             then 'YES' else 'NO'
         end) as YesOrNo
, $id, $followingID