<?php
echo "<table class=\"table table-hover table-bordered\">";
echo "<thead>";
echo "<tr>";
$result=mysqli_query($con,"SELECT day FROM time_slot ORDER BY day;");
while($row=mysqli_fetch_array($result))
{
$days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
$day = $row['day']-1;
$day = $days[$day];
echo '<th>';
echo $day;
echo '</th>';
}
echo "</tr>";
echo "</thead>";
require('../includes/connection.php');
$result=mysqli_query($con,"SELECT * FROM time_slot ORDER BY day DESC;");
while($row=mysqli_fetch_array($result))
{
echo "<tbody>";
echo "<tr>";这部分数据应垂直显示在表中,与日相关。
//This code to split time into intervals
$starttime = $row['start_time']; // your start time
$endtime = $row['end_time']; // End time
$duration = $row['slot_time'];
$array_of_time = array ();
$start_time = strtotime ($starttime); //change to strtotime
$end_time = strtotime ($endtime); //change to strtotime
$add_mins = $duration * 60;
while ($start_time <= $end_time) // loop between time
{
echo '<td>';
echo "<div align=\"center\">";
print_r(date ("h:i", $start_time) ."-". date("h:i", $start_time += $add_mins));
//
echo "</br><input type=\"radio\" name=\"texi\" value=\"1\" ></input>";
echo '</td>' ;
echo '</div>';
}
echo "</tr>";
echo "</tbody>";
}
mysqli_close($con);
echo "</table>
</div>
<input type=\"submit\" value=\"Book Slot\" class=\"button_drop\">
</form>";
?>我想在桌子上垂直显示与日有关的时隙。这是此代码的输出:

但我想显示时间,这是水平显示,应该是垂直显示。例如:第一行的1-3,3-5,5-7应显示在星期一以下,然后下一行应显示在星期二以下等等。
发布于 2017-01-10 10:56:14
尝试使用如下查询:
SELECT day FROM time_slot ORDER BY time_slot, day;这样就可以更容易地处理数据。我看不出你确切的数据结构,但看起来你应该得到7倍的01:00-03:00,然后是7倍的03:00-05:00等等。然后,您可以按照数据来自DB的顺序写出您的<td>。跟踪day值何时更改(或只需计数到7),并在那时启动一个新的<tr>。
https://stackoverflow.com/questions/41485370
复制相似问题