douding6266 2016-01-13 12:10
浏览 27

如何使用PHP显示时间表?

I have to display user schedule with created data,which i am getting as php array like below.

[0] => stdClass Object
        (
            [id] => 1            
            [slot_owner] => 2128
            [dateFrom] => 2016-01-01 05:00:00
            [dateTo] => 2016-01-01 06:00:00
        )

[1] => stdClass Object
(
    [id] => 2    
    [slot_owner] => 2129
    [dateFrom] => 2016-01-01 06:00:00
    [dateTo] => 2016-01-01 07:00:00   
)
[2] => stdClass Object
(
    [id] => 3    
    [slot_owner] => 2129
    [dateFrom] => 2016-01-01 07:00:00
    [dateTo] => 2016-01-01 08:00:00   
)
[3] => stdClass Object
(
    [id] => 4    
    [slot_owner] => 2128
    [dateFrom] => 2016-01-01 08:00:00
    [dateTo] => 2016-01-01 09:00:00   
)
[4] => stdClass Object
(
    [id] => 5    
    [slot_owner] => 2128
    [dateFrom] => 2016-01-01 09:00:00
    [dateTo] => 2016-01-01 10:00:00   
)

Here array is just sample and this can be set of date range and hours of the day. My requirement is to show the data in below format in a table.

slot_owner | from date | to date 
2128 | 2016-01-01 5:00:00 | 2016-01-01 06:00:00
2129 | 2016-01-01 6:00:00 | 2016-01-01 08:00:00
2128 | 2016-01-01 8:00:00 | 2016-01-01 10:00:00

Kindly provide me some solution. Thanks in advance.

Let me try to explorer my requirement. My client wants to implement a driver schedule. For this i have created a functionality where client can create entries by selecting a driver and start date and end date with start time and end time. Till here everything was fine, but now he is asking to add more drivers between existing date and time slot, i have also done this. My problem is the when i am fetching records from database it is showing all entries, where as it should be clubbed with date, time and driver. e.g. if A driver is assigned for 5AM to 10 AM on some date and other is assigned on same date after 10AM. Similar for all selected date range.

  • 写回答

1条回答 默认 最新

  • dongmu1390 2016-01-13 12:45
    关注

    Maybe I am wrong, but isn't it as simple as that?

    $array = ...;
    echo '<table><th><td>slot_owner</td><td>dateFrom</td><td>dateTo</td></th>';
    foreach ($array as $key => $object) {
        echo "<tr><td>". $object->slot_owner . "</td><td>" . $object->dateFrom . "</td><td>" . $object->dateTo ."</td></tr>";
    }
    echo "</table>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数