如果用户以特定顺序更改某些设置,我需要在数据库中设置时间戳记,我将在下面为您提供更多详细信息!
数据库:
#USERS
user_id user_name user_password ...
1 Adam ....
2 Bryan ....
3 Claire ....
4 Donna ....
#PROJECTS
project_id project_name project_status project_start project_delivery
1 Name 1 Inbox 2018-01-01 2018-01-10
2 Name 2 Working 2018-01-03 2018-01-12
3 Name 3 Delivered 2018-01-03 2018-01-04
4 Name 4 Delivered 2018-01-04 2018-01-04
当前查询:
$query = "
UPDATE projects
SET
project_name = '".$mysqli->real_escape_string($_POST['project_name'])."',
project_status = '".$mysqli->real_escape_string($_POST['project_status'])."',
project_start = '".$mysqli->real_escape_string($_POST['project_start'])."',
project_delivery = '".$mysqli->real_escape_string($_POST['project_delivery'])."'
WHERE
project_id = '".$mysqli->real_escape_string($_REQUEST['id'])."'
";
PHP:
基本上只是一个选择/选项和输入字段。请注意,project_status
是一个选择/选项。
问题:
简而言之,当项目从“收件箱”移动到“ project_start
中的工作状态”时,我想用今天的时间戳更新project_status
。
将项目从“正在工作”移至“已交付”时,project_delivery
也是如此。
关于如何实现这样的目标的任何想法吗?
答案 0 :(得分:0)
您可以这样尝试
SET project_start = CASE
WHEN project_status = 'Inbox' THEN CURDATE()
ELSE project_start
END
project_delivery = CASE
WHEN project_status = 'Working' THEN CURDATE()
ELSE project_delivery
END
WHERE ....