tags:

views:

39

answers:

3

Okay, so I'm relatively new to coding but I have a table w/ over 1000 codes in it.

Well, when people submit new information to it (via submit form) I want to be able to add the date/time to the table so that when I can print the 'latest 25'.

My questions are:

How do I add a column for the time? How do I add the time function to my submit line in my html? Will I get screwed because I'm going to have 1000 rows w/o a date and then whatever new rows w/ a date?

+1  A: 
  1. Use a DATETIME column. Allow Nulls

  2. Your existing records will have a null in the new column. This is OK.

  3. Use a query like this to get your top 25 records:

    SELECT column1, column2 FROM table ORDER BY MyDateTimeColumn DESC LIMIT 25

Robert Harvey
A: 

So when users submit data into the database via submit form how do I add datetime

...better expressed as a comment.
Robert Harvey
A: 

You can either set the new datetime column to default to a certain value (namely the current date/time) or you can include it in your insert statement.

insert into table (col1, col2, datetime_col) values ('whatever', 'whatever', now())

This is untested but would work in SQL Server...i imagine it would work in MySQL as well (actually the function in SQL Server is getdate() and a quick google search tells me that it is now() in MySQL).

thomas