Jump to content

Table help. Dates and Times


gott

Recommended Posts

Hello. I have a question for your expertise.

I currently have a mysql database with two tables, one with static information about tanks that will always stay the same (height, diameter, capacity, etc.) and another table with dynamic information that will change regularly (levels, products inside), approximately 3 times a day. at 7, 3 and 11. My question is how do I make the dynamic table work with dates and times? Is it better to have one giant table or generate a new one for every date and time. Also, what would be the best PHP functions to use to do the dates and times.

Also, I am using the tank number (varchar) as the primary key for each database as of right now.

Thank you for your help.
Link to comment
Share on other sites

Do you need to record all the changing information about the tanks, i.e. if it is 11 now, do you care what the values were at 3pm?  If you don't care, one table will suffice and will always hold the latest values.  If you need to record everything, you should have a second table that looks something like:

[tank_num] [levels] [products] etc.

in a one to many relationship with the main tanks table.

If the tank number is a physical thing linked to an actual number, you might consider using a separate internal autoincrement primary key - in my experience when I've used real information as a primary key, I've gotten into trouble, for instance if the format of tank numbers changes, or if you need to change numbers around.  But others may disagree.

For php date functions: [url=http://php.net/date]http://php.net/date[/url].

Also see mysql's date handling, which can save some programming work: [url=http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html]http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html[/url]

-pnj
Link to comment
Share on other sites

IMHO, a surrogate PK that is an integer always works better (at least for MyISAM tables were it doesn't matter).  MySQL does an excellent job of handling date/times, and there's nothing wrong with another table of "old" information that is timestamped.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.