dongye1912 2012-05-09 21:17
浏览 17
已采纳

PHP:MY​​SQL历史记录功能?

I save user inputs (comments) in these tables.

NEWS_COMMENTS
- id
- comment

PRODUCT_COMMENTS
- id
- comment
- product_id

I wanted to add a history feature to my website. Like;

-Someone commented on XX news.
-Someone commented on YY product.
-Someone commented on ZZ product.

You noticed the issue. I don't save timestamps or dates, so I can't be sure which comment comes first. It can be either the news comment or product comment.

Does MySQL has a feature to select last 24 hour inputs? For example,

NEWS_COMMENTS has 3 new entries in last 24 hours. PRODUCT_COMMENTS has 5 new entries in last 24 hours.

The query should select these 8 entries ordering by their entry date/timestamp.

Can I do this without altering my current pages? Can you provide a query?

  • 写回答

3条回答 默认 最新

  • dongshan7708 2012-05-09 21:21
    关注

    All you need to do is add a column with type timestamp and the option DEFAULT CURRENT_TIMESTAMP. You probably don't need any other modifications to your code - MySQL will do the magic to ensure that the timestamp is automatically filled in when you insert rows.

    Then you can get the rows from the last 24 hours with a simple query:

    SELECT col1, col2, ..., coln
    FROM yourtable
    WHERE yourtimestampcol > NOW() - interval 24 hour
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗