我试图显示商店的日期,时间和状态(如果商店是否开放)。我想将当前日期和时间以及状态显示为下拉框的标题,当用户点击该框时,他们会看到一周中的其他日期,时间和状态。我在下拉框中的数据工作正常,但标题不能正常工作。请看屏幕截图
我希望将日期,时间和状态作为标题放在下拉框标题中,并在表格中我希望显示其余时间。 (蓝色按钮不是下拉按钮,因为它是<button>
并且它会崩溃)。所以我也想用一个droppdown框替换这个按钮。感谢您的时间和建议。
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Timings </button>
<div class="collapse" id="collapseExample">
<div class="well">
<?php
date_default_timezone_set('Australia/Melbourne');
$datetime = new \DateTime();
$listItem = array('<li class="active">', '</li>');
$curDay = date('l');
$status = array( "Now Open" ,"Closed", "Opening Soon", "Closing Soon", "Open 24 hours", " ");
$times = $times = array(
1 => array('day' => 'Monday', 'open' => date( $row_DetailRS1['monO'] ), 'close' => date( $row_DetailRS1['monC'] )),
2 => array('day' => 'Tuesday', 'open' => date( $row_DetailRS1['tueO'] ), 'close' => date( $row_DetailRS1['tueC'] )),
3 => array('day' => 'Wednesday', 'open' => date( $row_DetailRS1['wedO'] ), 'close' => date( $row_DetailRS1['wedC']) ),
4 => array('day' => 'Thursday', 'open' => date( $row_DetailRS1['thurO'] ), 'close' => date( $row_DetailRS1['thurC']) ),
5 => array('day' => 'Friday', 'open' => date( $row_DetailRS1['friO'] ), 'close' => date( $row_DetailRS1['friC'] )),
6 => array('day' => 'Saturday', 'open' => date( $row_DetailRS1['satO'] ), 'close' => date( $row_DetailRS1['satC']) ),
7 => array('day' => 'Sunday', 'open' => date( $row_DetailRS1['sunO'] ), 'close' => date( $row_DetailRS1['sunC'] )) );
$html .= " <a href=''>"; echo $curDay; $html .="</a>
<table class='table table-striped' border='0' align='center' cellpadding='10' cellspacing='20'>
<tr>
<td>Days</td>
<td><span class='white-text' style='margin-right: 3em;'></td>
<td>Business Hours</td>
<td><span class='white-text' style='margin-right: 3em;'></td>
<td>Hours</td>
</tr>";
$i = 1;
$cd = $datetime->format('N');
$timenow = date("H:i:s", time());
// Create an array of day numbers that start with current day and loops around
$day_order = range($cd, 7);
if ($cd != 1) {
$day_order = array_merge($day_order, range(1, $cd-1));
}
foreach ($day_order as $daynum): {
$oc = $times[$daynum];
$openingTime = $oc['open'];
$closingTime = $oc['close'];
$openingSoon = date('H:i:sA', strtotime($openingTime)-3600);
$closingSoon = date('H:i:sA', strtotime($closingTime)-3600);
if ($cd == $daynum) {
if ($openingTime == ' ' && $closingTime == ' ') {
$s = $status[4];
}
elseif ($timenow < $openingSoon || $timenow > $closingTime ) {
$s = $status[1];
}
elseif ($timenow > $openingSoon && $timenow < $openingTime ) {
$s = $status[2];
}
elseif ($timenow > $closingSoon && $timenow < $closingTime ) {
$s = $status[3];
} else {
$s = $status[0];
}
} else {
$s = " ";
}
$html .= "<tr>";
$html .= "<td>". $oc['day']."</td>";
$html .= "<td> <span class='white-text' style='margin-right: 3em;'> </td>";
$html .= "<td>".$openingTime." to ".$closingTime."</td>";
$html .= "<td> <span class='white-text' style='margin-right: 3em;'> </td>";
$html .= "<td>".$s."</td>";
$html .= "</tr>";
}
$datetime->add(new \DateInterval('P1D'));
endforeach;
$html .= "</table>";
echo $html;
?>
答案 0 :(得分:2)
首先,你应该从视图中删除逻辑,在视图中混合逻辑是一个非常糟糕的做法,导致这种问题并使文件难以理解且难以维护。
您应该在控制器或其他文件中组装数组或数据列表,并使用控制器将数据发送到视图,视图应该只关注显示该数据。
你的问题是标签,你有一堆真正的标签,这就是问题所在。
例如,您有span
个标签打开,但永远不会关闭。
我建议您取出逻辑,完全删除<?php ... ?>
标记并清理视图。在那之后你会看到一切都清楚。