| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|MYSQL IF statement,|
if value= this, show this
If there is a field named "status", it can either have 0 or 1 as value. when we select the field, is there any way where we can display "Accepted" for a 1, and "Rejected" for a 0 ?
IF status=0 Display "Rejected"
IF status=1 Display "Accepted"
in a simple select query ?
you could probably do something using a temporary table...
Phranque - either I or you have read the question wrong. Surely this is a simple if() ?
SELECT IF(STATUS = 0, 'Rejected', 'Accepted') from TABLE
If the status field had another value such as 2 for "On Hold" then you can just nest the ifs.
SELECT IF(STATUS = 0, 'Rejected', IF(STATUS = 1, 'Accepted', 'On Hold')) from TABLE
Nested example . . .
select username,firstname,lastname,if(status = 0, 'Rejected', 'Accepted') from table;
Thats cool, Thanks everyone
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved