douzhizao0270 2017-02-20 11:44
浏览 58

使用HTML创建时间表 - PHP - MySQL

I want to make a timetable in a HTML-table. I have a database structure set up and now I have trouble with displaying the database data in the HTML-table correctly.

My database structure involves:

enter image description here

The days are numbered by day_nr where 1 = monday, 2 = tuesday, 3 = wednesday, 4 = thursday and 5 = friday. The hours are numbered by hour_nr from 1 to 10.

Here is an example of what I eventually want to create.

CLICK ME FOR IMAGE]

Some code:

<?php
session_start();
    // Connect MySQL Database
    require("function.php");
    $con = sql_connection();
        // Select data from database (select the right table)
    $result01 = mysqli_query("SELECT teacher_code, day_nr, hour_nr, subject_code, room_nr, class_code FROM `lesson`");

    echo "<table class='table table-striped table-bordered student_table'>
            <thead class='thead-inverse'> 
                <tr>
                    <th class='start_time'></th>
                    <th>Monday</th>
                    <th>Tuesday</th>
                    <th>Wednesday</th>
                    <th>Thursday</th>
                    <th>Friday</th>
                </tr>
            </thead>";
  • 写回答

2条回答 默认 最新

  • douyi0902 2017-02-20 13:09
    关注

    You need to create a data structure in your php program representing your time table.

    Perhaps you should create an array with an element for each day. Each element of that top level array can itself contain an array, with an element for each time slot in the day.

    Then each time slot element can contain an array, with an element for each item to represent in the time slot.

    You can then populate this data structure as you retrieve your MySQL result set. You can then render it -- write it to HTML -- using PHP code.

    Explaining how to create and use of data structure is, in my opinion, beyond the scope of what you should expect in a Stack Overflow answer.

    评论

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目