1

我正在制作一个音乐节的时间表网站。本网站的目的是让人们选择他们想看到的行为并为活动编制自己的个人时间表。目前该网站有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>

4

1 回答 1

0

我会使用 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']}";
   }
}

...未经测试的代码,但这就是要点。我保证那里有一些语法和逻辑错误,但这是一个概念和一种方法。

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

于 2010-08-16T21:39:26.217 回答