Jump to content


Photo

dynamic field "default"?


  • Please log in to reply
2 replies to this topic

#1 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 May 2006 - 01:55 PM

Working on a small calendar project where there is an event date and display dates -- on and off. I have controled this with three fields in mysql: event_date, date_on, and date_off. All of the fields default to 0000-00-00, but I'd like to change that to today's date for date_on, and have date_off default to whatever is sent in event_date (which might not even be possible). One thing's for sure -- refman says I'd have to change all to the timestamp type to do anything like this (and I can only record the current timestamp).

So, is all hopeless in mysql and must be hardcoded in php?

idea:
viewing a particular calendar page could fire something like this
UPDATE `table` SET `date_on` = DATE_ADD(`event_date`, INTERVAL -1 MONTH); WHERE `date_on` = '0000-00-00'
will that work?

#2 fenway

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

Posted 16 May 2006 - 02:28 PM

Unforutnately, the defaults for columns must be literals, so you can't do it the "easy way". However, the update statement you posted should be just fine (minus the extraneous semi-colon).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 16 May 2006 - 02:34 PM

[!--quoteo(post=374283:date=May 16 2006, 09:28 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 16 2006, 09:28 AM) View Post[/div][div class=\'quotemain\'][!--quotec--](minus the extraneous semi-colon).
[/quote]

oops -- old habits die hard [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users