0

I'd like to add a timestamp to articles I upload to my website, which reads the time and date the article was uploaded. I've got a database, as well as a working connect.php. In this database, I've created a table with a "date" field (type: date). What can I do to get the timestamps working?

3
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by diafol
0

I'm confused by your question. The date column would be a column of your articles table, as would the message body column. For example, the following might be a structure of your articles table:

id | title | body | date
------------------------

Your php code would then populate all four columns at once.

0

WHat do you mean by timestamp? Datetime, e.g. 2012-06-24 13:09:34 or UNIX timestamp, e.g. 1340566711 . If you're saving as 'date', you're only saving '2012-06-24'?

Edited by diafol

0

By timestamp, I mean a line of text at the top of an article, reading "posted on Y/M/D". As for the confusion, I'm a bit confused myself. I know that databases are supposed to work with rows and columns, but PHPMyAdmin just lets me create a table with fields. So I created a table with a single field, which I named "date".

0

Ok, you probably need to take a deep breath and read up on MySQL, and possibly the phpMyAdmin application. I must be honest - I hate phpMyAdmin, so I use other GUIs. One you may find useful is SQLyog (Community Version), available from here:

http://code.google.com/p/sqlyog/downloads/detail?name=SQLyog-10.1.1-0Community.exe&can=2&q=

That will allow you to add/update/delete easily.

Also, try not to use reserved words (like 'date') for fieldnames. You can do so of course, but you MUST enclose them in `backticks`, otherwise you'll get MySQL errors. It's good practice to enclose all tables and fields in backticks anyway.

0

phpMyAdmin fields are the equivalent of table columns. So if you ARE using phpMyAdmin, you'd want to create one table with multiple fields ... title, body, and date.

0

I actually just got that (inputed an SQL command to create a new column, thereby creating a field).

0

inputed an SQL command to create a new column, thereby creating a field

That's a bit hardcore! :)

0

How so? MyAdmin has a command input (or command line) option. I just typed ALTER TABLE news ADD postdate VARCHAR(1000);

0

Hit the 'structure' tab on a table and then you can add fields via the interface.

BTW - take care which MySQL version you have, before 5.0.3 varchar will have max length 0-255

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.