Reputation: 9007
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>
my question is how can i generate table with todays hours dynamically without having to hardcoded it in html ? i need this table to include a tr for each hr of the day (24hr).
My aim : i'm creating a booking page for my clinic website, i have all visits to that clinic stored in mysql as "visit,name_patient,date,time,clinic_num",
i fetch all records for today from db and i want to display it in a table.
Question
so can some one tell me what is the simplest logic flow to generate such a table ?
how to generate rows with today's hrs "9am,10am,11am"
Note: http://apps.zarjay.net/scheduler/ this looks like what i want but still time is hard coded. most other calendar plugins are really complex and over kill for wt i want
etc ?
Upvotes: 0
Views: 951
Reputation: 10469
This is the simplest way to do it that I'm aware of:
<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>
Change the values for the range(0,23)
to suit your needs
Here it is applied to your 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>
Upvotes: 1