php mysql今天,昨天和日期从数据库 [英] php mysql today, yesterday and date from database

查看:214
本文介绍了php mysql今天,昨天和日期从数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在用户注销时保存日期,以便他可以找到上次登录的日期,我正在使用以下代码:

I am trying to save date when the user log out so that he can find the date of the last login, I am using this code:

 mysql_query("UPDATE `table` SET `lastLog` = now() WHERE user_id = '".$_SESSION['userID']."'"); 

这将给出上次登录的历史记录和时间,但我希望代码显示今天如果最后一次登录是昨天,昨天如果最后一次登录是昨天的话。昨天以后,如果我在三天前退出,我只想显示一个常规日期,那么值应该是这样的:8/7/2014。有没有办法做到这一点。

which will give the history and the time of the last login correctly but I want the code to show the word today if the last login was today and yesterday if the last login was yesterday. and after yesterday I want to show only the regular date for example if I logged out three days ago then the value should be like this: 8/7/2014. is there an easy way to do it.

推荐答案

    $result = mysql_query("select lastLog from `table` WHERE user_id = '".$_SESSION['userID']."'"); 
    while($row = mysql_fetch_array($result))
        {
         $last_login = $row['lastLog '];
        }

if($last_login  == date('d.m.Y'))
echo "its today";

if($last_login  == date('d.m.Y',strtotime("-1 days")))
echo "it was yesterday";

else
echo 'it was '.$last_login;

这篇关于php mysql今天,昨天和日期从数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆