Requesting Custom Fields from MySQL
I think there is a better name for what I am trying to do.
I have this.
SELECT * FROM user_bans WHERE user_id='{$user->id}'
What I wa开发者_Go百科nt is something like this.
SELECT *, active = (DATE(expire) > NOW() ? 1 : 0) FROM user_bans WHERE user_id='{$user->id}'
The expire field is a datetime field. I want to see if the ban has expired and set the active value accordingly.
What syntax do I need to use to do this?
This might be your need!
SELECT *, IF(DATE(expire) > CURDATE() , 1 , 0) AS `active`
FROM user_bans WHERE user_id={$user->id}
精彩评论