开发者

Requesting Custom Fields from MySQL

开发者 https://www.devze.com 2023-02-06 11:45 出处:网络
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}\'

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

精彩评论

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