Manoj Nayak
Manoj Nayak

Reputation: 2509

Formatting mysql query output

In my query I want to check if the users with the specified permissions exists or not. Presently I am using the below query. It will retrieve the rows of authorised users with the specified conditions.

select a.ixUserAuthorization from tblechecklistuserroleassignmentxref r
inner join tblechecklistuserrole u on u.ixUserRole=r.ixUserRole and u.sname='Initiator'
inner join tblechecklistuserauthorization a on a.ixUserAuthorization=r.ixUserAuthorization
and a.ixcustomer='1'and a.ixprogram='1'and a.ixworkpackage='1'and a.ixactivity='1' and a.ixUser='626e28e8-e67a-4d11-8d2c-129d0ab79e96';

If any rows are returned i want to display the result as true ,If no rows are returned from the above query I want to display the result as false.

How can I modify to obtain the result as true or false .

Upvotes: 0

Views: 206

Answers (2)

Uttara
Uttara

Reputation: 2534

use function mysql_num_rows

ex:

if(mysql_num_rows($result))
  echo "true";
else
   echo "false";

where $result is the result of your query

Upvotes: 1

Romil Kumar Jain
Romil Kumar Jain

Reputation: 20745

SELECT CASE 
         WHEN Count(*) >= 1 THEN 'true' 
         ELSE 'false' 
       END AS Answer 
FROM   (SELECT a.ixUserAuthorization 
        FROM   tblechecklistuserroleassignmentxref r 
               INNER JOIN tblechecklistuserrole u 
                 ON u.ixUserRole = r.ixUserRole 
                    AND u.sname = 'Initiator' 
               INNER JOIN tblechecklistuserauthorization a 
                 ON a.ixUserAuthorization = r.ixUserAuthorization 
                    AND a.ixcustomer = '1' 
                    AND a.ixprogram = '1' 
                    AND a.ixworkpackage = '1' 
                    AND a.ixactivity = '1' 
                    AND a.ixUser = '626e28e8-e67a-4d11-8d2c-129d0ab79e96') a 

Upvotes: 1

Related Questions