user2512816
user2512816

Reputation:

Return Yes or No PHP Query

I have the following query:

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

I was wondering how I would return if the result is YES or NO based off the 0 and 1 count for if the relationship exists?

Upvotes: 0

Views: 125

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

Here is one way:

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

Upvotes: 1

Related Questions