How do I create a php script that stores and displays when an article was last edited using PHP and MySQL.
A:
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.
Brendan Long
2009-11-28 04:18:34
How would the code look like?
dsj
2009-11-28 04:20:26
If you have phpMyAdmin, just go to the table and at the bottom of the page it will say Add [1] field(s)... Click [Go] on that line. Then on the next page choose the options I gave above.
Brendan Long
2009-11-28 04:27:19
+3
A:
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.
pygorex1
2009-11-28 04:34:10