Jump to content


Photo

Automatic timestamp


  • Please log in to reply
5 replies to this topic

#1 Silus

Silus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 August 2006 - 05:37 AM

I'm really new to mysql, but I would like to add a timestamp to a row when it is added automatically.

Thanks.

#2 Silus

Silus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 August 2006 - 06:08 AM

I figured it out.

I had to

alter table stats add timestamp timestamp;

then when I added data from a script I put null into the timestamp field

echo "insert into stats values ( $input4 , $input5 , $input6 , $input13 , $input14 , $input15 , $input16,null );"


the $input#'s are just some script variables I added to the table.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 August 2006 - 02:59 PM

You should probably use a column list for your INSERT statements.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 Silus

Silus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 August 2006 - 04:49 PM

Probably so as it stopped working for no apparent reason.

BTW  can you give an example of a column list and why is it preferrable?

Thanks

#5 Silus

Silus
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 August 2006 - 05:17 PM

I see that it broke actually because a scipt was returning data differently than previously(I don't know why this is the case).

Anyways, I swapped to the column list where I list the column names then the data that goes in em

insert into stats (cola,colb) values($input3,$input4);

It made it much easier to see what was exactly causing the error.

Thanks for the help

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 August 2006 - 09:11 PM

Glad you got it working... I always thought that have no column list should be a syntax error.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users