在 PHP 中创建日历
最近,有人非常好心地给了我一些代码,用于创建一个在 HTML 中模拟时间表的表 - 下面是代码,
function make_row( $slot , array $list )
{
$output = '';
$output .= '<tr><td>' . $slot . '</td>';
for ( $i = 1; $i <= 7 ; $i++ )
{
$details = ' ';
if ( isset($list[ $i ]) )
{
$details = $list[ $i ];
}
$output .= '<td>' . $details . '</td>';
}
$output .= '</tr>';
return $output;
}
$timeslot = '';
$item = array();
while ($eventrow = mysql_fetch_array($sqlevents))
{
$timeslot = $eventrow['PreferredStart'];
$day = (int)$eventrow['idDay'];
if ( !is_array( $item[ $timeslot ] ) )
{
$item[ $timeslot ] = array();
}
$item[ $timeslot ][ $day ] = $eventrow['EventDetails'];
}
foreach( $item as $slot => $list )
{
echo make_row( $slot, $list );
}
但是,我的数据库表设置已更改。我现在有半小时的时间,而不是一小时的时间。该表呈现正确,但我试图确保如果有人输入约会,则整个区块都会在日历中标记,而不仅仅是开始时间。有人可以帮我添加结束时间以及之间的时间段吗?
非常感谢, 布雷特
Recently, someone very kindly gave me some code for creating a table that simulated a schedule in HTML - below is the code
function make_row( $slot , array $list )
{
$output = '';
$output .= '<tr><td>' . $slot . '</td>';
for ( $i = 1; $i <= 7 ; $i++ )
{
$details = ' ';
if ( isset($list[ $i ]) )
{
$details = $list[ $i ];
}
$output .= '<td>' . $details . '</td>';
}
$output .= '</tr>';
return $output;
}
$timeslot = '';
$item = array();
while ($eventrow = mysql_fetch_array($sqlevents))
{
$timeslot = $eventrow['PreferredStart'];
$day = (int)$eventrow['idDay'];
if ( !is_array( $item[ $timeslot ] ) )
{
$item[ $timeslot ] = array();
}
$item[ $timeslot ][ $day ] = $eventrow['EventDetails'];
}
foreach( $item as $slot => $list )
{
echo make_row( $slot, $list );
}
However, my DB table setup has changed. I now have half hour slots instead of full hour ones. The table renders correctly, but I am trying to ensure that if someone enters an appointment, then the whole block is marked in the calendar, not just the start time. Can someone help me to add the end time, as well as the timeslots in between?
Many thanks,
Brett
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不知道数据库结构或生成
$sqlevents
的 sql 查询,这个问题很难回答,但看起来时间段只是直接从数据库中获取:您可以通过查找结束时间来更改它(我假设数据库中名为
PreferredEnd
,但显然您必须自己检查一下,因为我不知道您的数据库架构)并将两者添加在一起:现在您的
$ timeslot
var 中应该同时包含开始时间和结束时间。This is pretty tough to answer without knowing the database structure or the sql query that produced
$sqlevents
, but it looks like the timeslot is simply taken straight from the database:You could change this by finding the end time (I assume named
PreferredEnd
in the database, but you'll obviously have to check that for yourself, as I don't know your database schema) and adding the two together:Now your
$timeslot
var should have both start and end time in it.