开发者

Creating a calendar in PHP

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 = '&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['id开发者_StackOverflow中文版Day'];

      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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜