HTML
<table class="" id="schedule">
<thead>
<tr>
<th><input value="Time" type="text"></th>
<th><input value="Monday" type="text"></th>
<th><input value="Tuesday" type="text"></th>
<th><input value="Wednesday" type="text"></th>
<th><input value="Thursday" type="text"></th>
<th><input value="Friday" type="text"></th>
</tr>
</thead>
<tbody>
<tr>
<th><input value="9:00am" type="text"></th>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr></tbody></table>
我的问题是如何动态生成今天的表格而无需在html中对其进行硬编码? 我需要这个表格,包括当天每小时(24小时)的tr。
我的目标:我正在为我的诊所网站创建一个预订页面,我将所有访问该诊所的内容存储在mysql中,如“visit,name_patient,date,time,clinic_num”,
我从db获取今天的所有记录,我希望将其显示在表格中。
问题
所以有人可以告诉我生成什么是最简单的逻辑流程 这样的桌子?
如何使用今天的小时“9 am,10am,凌晨1点”生成行
注意: http://apps.zarjay.net/scheduler/这看起来像我想要的但仍然是时间硬编码。大多数其他日历插件非常复杂,并且对于我想要的
而言过度杀戮etc ?
答案 0 :(得分:1)
这是我所知道的最简单的方法:
<table>
<?php foreach (range(0, 23) as $i) : ?>
<tr>
<td><?php echo date('ha', mktime($i, 0)); ?></td>
<td>What ever you want here</td>
</tr>
<?php endforeach; ?>
</table>
更改range(0,23)
的值以满足您的需求
此处它适用于您的HTML:
<table class="" id="schedule">
<thead>
<tr>
<th><input value="Time" type="text"></th>
<th><input value="Monday" type="text"></th>
<th><input value="Tuesday" type="text"></th>
<th><input value="Wednesday" type="text"></th>
<th><input value="Thursday" type="text"></th>
<th><input value="Friday" type="text"></th>
</tr>
</thead>
<tbody>
<?php foreach (range(0, 23) as $i) : ?>
<tr>
<th><input value="<?php echo date('ha', mktime($i, 0)); ?>" type="text" /></th>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>