I have a small website I'm working on and for this project I want to use phpMyAdmin's user interface to edit items directly in the database instead of building an admin user interface for the website. I'm going to quick edit items like this:
(source: forumbilder.se)
(Not actually using wordpress, just took a random database table to use as an example)
The problem is that I have a column holding the datetime for when the row was last edited, and I don't know how to make said column update itself automatically after an edit like this is made. Any help would be appreciated.
To add a date information in PHPMyAdmin you need to log in the PHPMyAdmin interface and then to enter the 'Insert' tab. Then you can choose the appropriate Insert functions for each field using the drop-down list in the functions column.
Learn MySQL from scratch for Data Science and Analytics You can use now() with default auto fill and current date and time for this. Later, you can extract the date part using date() function. Let us set the default value with some date.
In phpMyAdmin, navigate to the table in question and click the "Operations" tab. On the left under Table Options you will be allowed to set the current AUTO_INCREMENT value. Save this answer.
You can implement this by using a TIMESTAMP column appplying the ON UPDATE CURRENT_TIMESTAMP
clause - See https://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
So if you are creating the table from scratch:
CREATE TABLE t1 (
...
post_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
post_content ...
...
);
or if you already have the table, you can alter the relevant column:
ALTER TABLE t1 MODIFY post_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Note that the column definition in both examples sets a default value of the current date/time for new records. That is usually how this feature tends to be implemented, but of course your requirement may vary, so you may wish to set the default differently.
UPDATE: If you wish to implement this using phpMyAdmin:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With