在HTML表单中处理时间

时间:2013-05-20 14:46:48

标签: php mysql

确定。我正在为我的网络电台工作一个节目安排经理。我到目前为止已经到了,但似乎无法弄清楚在编辑时处理节目的播出时间和结束时间。以下是表格中的代码。

时间以24小时格式存储在HTML数据库中,以便于排序。

如果您需要查看其余代码:https://github.com/phillf/ProgramScheduleManager

代码来自:admin / editShow.php:

    <td>What time does this show start?</td>
    <td>
        <select name="AirTime">
    <?php for($i = 0; $i < 24; $i++): ?>
            <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option>
        <?php endfor ?>
        </select>
    </td>
<tr>
<tr>
    <td>What time does the show end?</td>
    <td>
        <select name="EndTime">
        <?php for($i = 0; $i < 24; $i++): ?>
            <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option>
        <?php endfor ?>
        </select>
    </td>
</tr>

1 个答案:

答案 0 :(得分:1)

假设您已完成数据库查询并将当前播出时间设置为$airTime,则可以设置selected属性,如下所示:

<select name="AirTime">
    <?php for($i = 0; $i < 24; $i++): ?>
         <option value="<?= $i; ?>:00:00" <?php if ($i == $airTime) { echo 'selected'; } ?> ><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option>
    <?php endfor ?>
</select>

同样适用于EndTime