开发者

PHP/MySQL last edit script?

How do I create a php script that stores and displays when an article was last edited using PHP 开发者_如何学Cand MySQL.


You can create a TIMESTAMP column in MySQL that will auto-update whenever it's UPDATed. Try running this SQL from the MySQL client / PHPmyadmin

CREATE TABLE articles (
 id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
 title VARCHAR(256),
 content TEXT,
 modified_date TIMESTAMP
);

INSERT INTO articles VALUE (1, 'my title', '<p><b>some content</b></p>', NULL);

SELECT * FROM articles;

UPDATE articles SET title='title update';

SELECT * FROM articles;

So, whenever you update an article or create a new article the timestamp value will be updated.


I'm making the following assumptions:

  • You have a control panel you wrote in php that you add or update articles in
  • Your articles are in a table in your database, one to a row (I will call this your articles table)
  • You have access to phpMyAdmin or know how to add MySQL columns manually

So to make it so whenever one of your articles is added or updated it updates a timestamp, create a new column with type: TIMESTAMP, default: CURRENT_TIMESTAMP, attributes: on update CURRENT_TIMESTAMP.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜