Reputation: 57
Ok. I am working on a Program Schedule Manager for my internet radio station. I have come thus far but can't seem to figure out dealing with the Air Time and End Time of show when editing. Below is the code from the form.
The times are stored in the HTML database as 24-hour format to make sorting easier.
If you need to look at the rest of the code: https://github.com/phillf/ProgramScheduleManager
Code from: 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>
Upvotes: 0
Views: 99
Reputation: 780724
Assuming you've done a database query and put the current air time in $airTime
, you set the selected
attribute like this:
<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>
And similarly for EndTime
.
Upvotes: 1