【问题标题】:Dynamically check timetable for clashes - jquery/php动态检查冲突的时间表 - jquery/php
【发布时间】:2010-08-16 18:26:47
【问题描述】:

我正在制作一个音乐节的时间表网站。本网站的目的是让人们选择他们想看到的行为并为活动编制自己的个人时间表。目前该网站有 2 张桌子:

  1. 在 节日
  2. 用户的个人时间表

这是我的问题。每次将完整列表中的行为添加到用户的个人时间表时,我都想要一个函数来遍历用户时间表的每个表行并突出显示冲突。然后这种冲突将具有不同的格式(为了论证,假设它会将行的背景变为红色,以表示冲突)。

我该怎么做?

表格代码:

<table id="fri_myTimes">
    <thead>
    <tr><th>Act</th>
    <th>Start Time</th>
    <th>End Time</th>
    <th>Duration</th>
    </tr></thead>
    <tbody>
<tr id="band-Young-Guns class="Main">
<td>Young Guns</td>
<td>12:00:00</td>
<td>12:30:00</td>
<td>30</td>
<td><div id="btn-Young-Guns" class="del">&nbsp;</div></td>
</tr>
<tr id="band-Frankie-And-The-Heartstrings" class="NME-/-Radio-1">
<td>Frankie And The Heartstrings</td>
<td>12:00:00</td>
<td>12:30:00</td>
<td>30</td>
<td>
<div id="btn-Frankie-And-The-Heartstrings" class="del">&nbsp;</div></td></tr>
</tbody>

【问题讨论】:

  • 如何添加第三个表以使其更加规范化。有一个 ID 和每 15 分钟一次的时间(8:00、8:15、8:30 等),并将每个动作分配给一个时间 ID,然后如果两个匹配,你就有冲突。在 Acts 表中,添加一个持续时间字段或将时间设置为“start”(开始时间的 ID)和“end”(结束时间的 ID),如果有重叠,则存在冲突。
  • 我想我明白了。每次我从完整列表附加到用户列表时,我将如何运行此功能?这也是在 jq 代码还是 php 代码中?

标签: php jquery datetime timetable


【解决方案1】:

我会使用 PHP,在表中插入新时间,然后为用户布置用户时间表。在布置时间表时,选择所有用户选择的行为并按时间顺序显示

user
id | username | email | etc
33 | BillyBob | ...   |
... etc ...

timetable
id           | user_id | act_id
1            | 33      | 5
2            | 33      | 6
3            | 33      | 19

acts

id | start_time        | end_time         | title             | description
5  | 2010-11-20 11:00  | 2010-11-20 13:00 | Smashing Tomatoes |
6  | 2010-11-20 12:00  | 2010-11-20 14:00 | Stray Dogs        |
7  | 2010-11-21 11:00  | 2010-11-21 13:00 | Mister Googo      |
....
19 | 2010-11-21 12:00  | 2010-11-21 14:00 | Reeses Pieces     |

select t.*, a.title, UNIX_TIMESTAMP(a.start_time) as epoch_start, UNIX_TIMESTAMP(a.end_time) as epoch_end from timetable t join acts a on ( t.act_id = a.id ) where t.user_id = 33;

$timetable = array ();
while ( $rs = mysql_fetch_array ( $r, MYSQL_ASSOC ) )
{
    foreach ( $timetable as $tt )
    {
        if ( $rs['epoch_start'] > $tt['epoch_start'] and $rs['epoch_start'] < $rs['epoch_end'] )
        {
            $rs['conflict'] = $tt['id'];
        }
    }

    $timetable[$rs['id']] = $rs;
}


foreach ( $timetable as $toss => $tt )
{
   echo $tt['title'];
   if ( $tt['conflict'] )
   {
       $conflict = $timetable[$tt['conflict']];
       echo "note: this time conflicts with {$conflict['title']}";
   }
}

...未经测试的代码,但这就是要点。我保证其中存在一些语法和逻辑错误,但这是 a 概念和一种方法。

我离开了 time_id 的东西;它并没有那么大的帮助。

【讨论】:

    猜你喜欢
    • 2016-05-02
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多