-4

我想将学校时间表/课程表存储到 mysql 数据库中。需要帮助理解。这是php表单

Period No.  Monday      Tuesday     Wednesday   Thursday    Friday      Saturday

1           Subject     Subject     Subject     Subject     Subject     Subject
            Classrrom   Classroom   Classroom   Classroom   Classroom   Classroom

2           Subject     Subject     Subject     Subject     Subject     Subject
            Classrrom   Classroom   Classroom   Classroom   Classroom   Classroom

3           Subject     Subject     Subject     Subject     Subject     Subject
            Classrrom   Classroom   Classroom   Classroom   Classroom   Classroom

4           Subject     Subject     Subject     Subject     Subject     Subject
            Classrrom   Classroom   Classroom   Classroom   Classroom   Classroom

5           Subject     Subject     Subject     Subject     Subject     Subject
            Classrrom   Classroom   Classroom   Classroom   Classroom   Classroom

6           Subject     Subject     Subject     Subject     Subject     
            Classrrom   Classroom   Classroom   Classroom   Classroom   

7           Subject     Subject     Subject     Subject     Subject     
            Classrrom   Classroom   Classroom   Classroom   Classroom                                                                                
8           Subject     Subject     Subject     Subject     Subject     
            Classrrom   Classroom   Classroom   Classroom   Classroom     

如何将此表格插入数据库或此类学校时间表的任何其他解决方案。每天需要不同的科目和教室,总时间是 8. 请帮帮我

4

2 回答 2

1

您可以按照您要求的方式进行操作。

CREATE TABLE timetable
    (`Period` int, `Monday` varchar(17), `Tuesday` varchar(17), `Wednesday` varchar(17), `Thursday` varchar(17), `Friday` varchar(17), `Saturday` varchar(17))
;

INSERT INTO timetable
    (`Period`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday`)
VALUES
    (1, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (2, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (3, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (4, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (5, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (6, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (7, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom'),
    (8, 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom', 'Subject-Classroom')
;

你有这样的输出:

+--------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+
| PERIOD |            MONDAY |           TUESDAY |         WEDNESDAY |          THURSDAY |            FRIDAY |          SATURDAY |
+--------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+
|      1 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      2 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      3 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      4 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      5 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      6 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      7 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
|      8 | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom | Subject-Classroom |
+--------+-------------------+-------------------+-------------------+-------------------+-------------------+-------------------+

现在使用PHP,你可以这样解析它:

<?php
     $class = explode("-", $class);
     // Subject: $class[0];
     // Classroom: $class[1];
?>
于 2012-10-15T08:50:10.907 回答
1
  1. 您应该创建一个包含 4 个字段的数据库表:日期、期间、主题和教室。
  2. 创建表单,为周一第一节课命名元素,例如“1-1-subject”,为周三第 5 节课命名“3-5-subject”。
  3. 遍历 post 值并将它们保存到 db,您可以使用 PHP 的 explode 函数轻松地将字段名称分开。
于 2012-10-15T08:56:14.193 回答