在 PHP 中创建日历

发布于 2024-11-05 15:00:31 字数 1094 浏览 0 评论 0原文

最近,有人非常好心地给了我一些代码,用于创建一个在 HTML 中模拟时间表的表 - 下面是代码,

    function make_row( $slot , array $list )
   {
      $output = '';
      $output .= '<tr><td>' . $slot . '</td>';
      for ( $i = 1; $i <= 7 ; $i++ )
      {
         $details = '&nbsp;';
         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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰◇生如夏花灿烂 2024-11-12 15:00:31

如果不知道数据库结构或生成 $sqlevents 的 sql 查询,这个问题很难回答,但看起来时间段只是直接从数据库中获取:

$timeslot = $eventrow['PreferredStart'];

您可以通过查找结束时间来更改它(我假设数据库中名为 PreferredEnd ,但显然您必须自己检查一下,因为我不知道您的数据库架构)并将两者添加在一起:

$timeslot_start = $eventrow['PreferredStart'];
$timeslot_end   = $eventrow['PreferredEnd'];   // I'm gonna assume this is right

$timeslot = $timeslot_start.'-'.$timeslot_end; // Make a new field combining both

现在您的 $ 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:

$timeslot = $eventrow['PreferredStart'];

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:

$timeslot_start = $eventrow['PreferredStart'];
$timeslot_end   = $eventrow['PreferredEnd'];   // I'm gonna assume this is right

$timeslot = $timeslot_start.'-'.$timeslot_end; // Make a new field combining both

Now your $timeslot var should have both start and end time in it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文