【问题标题】:How to create table with today calendar ? jquery and php如何使用今天的日历创建表格? jquery 和 php
【发布时间】:2012-12-07 15:20:30
【问题描述】:

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 获取今天的所有记录,我想将其显示在表格中。

问题

  1. 所以有人可以告诉我生成的最简单的逻辑流程是什么 这样的表?

  2. 如何使用今天的时间“9am,10am,11am”生成行

注意: http://apps.zarjay.net/scheduler/ 这看起来像我想要的,但时间仍然是硬编码的。大多数其他日历插件真的很复杂,而且对于我想要的 wt 来说太过分了

etc ?

【问题讨论】:

  • 即使你硬编码,我也想不出少于 24 小时的一天,所有需要动态的肯定是日期输入
  • 只需使用 JQuery UI。他们已经发明了那个轮子。 jqueryui.com

标签: php jquery codeigniter calendar


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2014-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    相关资源
    最近更新 更多