开发者

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}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜