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条)

报告相同问题?

悬赏问题

  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚