简体   繁体   English

如何基于当前时间戳在mysql数据库中创建动态更改表

[英]How to create dynamically changing table in mysql database based on current timestamp

Hi I have some employee records in MySQL db, and I use PHP to display those records as report. 嗨,我在MySQL数据库中有一些员工记录,我使用PHP将这些记录显示为报表。 Now I am stuck with some issue, my employee record have future details like whether they are available in a position or not at some point of time. 现在,我遇到了一些问题,我的员工记录中包含未来的详细信息,例如在某个时间点是否可用。 It records details upto 16 weeks ahead of current week. 它会在本周之前的16周之前记录详细信息。 Now I implemented like for each week separate column in the DB, that I created for testing. 现在,我像每周一样在数据库中实现为测试创建的单独列。

Screenshot of my DB - Dates are highlighted using yellow 我的数据库的屏幕截图-日期以黄色突出显示 在此处输入图片说明

But the problem now is I have to manually delete the first date column and add new column at end every week and also I have to update the HTML Form which I used for getting input data. 但是现在的问题是,我必须手动删除第一个日期列,并在每周末尾添加新列,而且还必须更新用于获取输入数据的HTML表单。

<form>
                    <table>
                          <tr>
                            <td>Name:</td>
                            <td colspan="5"><input type="text" size="40"/></td>
                          </tr>
                          <tr>
                            <td>Domain: </td>
                            <td><input type="text" size="10"/></td>
                            <td>Project: </td>
                            <td><input type="text" size="20"/></td>
                            <td>Area Of Testing:</td>
                            <td><input type="text" size="20"/></td>
                          </tr>
                          <tr>
                            <td>EmployeeID:</td>
                            <td colspan="2"><input type="text" size="6"/></td>
                            <td>TKID: </td>
                            <td colspan="2"><input type="text" size="7"/></td>
                          </tr>

                          <tr>
                            <td colspan="6">Billability:</td>
                          </tr>
                          <tr>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/29</td>
                            <td><input type="text" size="4"/></td>
                            <td>07/06</td>
                            <td><input type="text" size="4"/></td>
                          </tr>
                          <tr>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                          </tr>
                          <tr>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                          </tr>
                          <tr>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                          </tr>
                          <tr>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <td><input type="text" size="4"/></td>
                            <td>06/22</td>
                            <<td><input type="text" size="4"/></td>
                          </tr>

Is their any way to overcome such situation dynamically ? 他们有办法动态地克服这种情况吗? Or Is their any kind of script which will automatically trigger these update on every week ? 还是他们的脚本会每周自动触发这些更新?

Ideally you would have another table with: 理想情况下,您将有另一个表:

EmpID Date Record EmpID日期记录

Then you would have: 然后您将拥有:

1, "2015-05-01", 3 1,“ 2015-05-01”,3

2, "2015-05-02", 1 2,“ 2015-05-02”,1

etc 等等

Then just add the dates whenever they are inserted, or run a cronjob everyweek to add 7 days to every employee. 然后,只需在插入日期时就添加日期,或者每周运行一次cronjob即可为每位员工增加7天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM