如何在php中插入mysql的时间表

时间:2012-10-15 08:45:12

标签: php mysql

我想将学校的时间表/班级时间表存储到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.请帮帮我

2 个答案:

答案 0 :(得分: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];
?>

答案 1 :(得分:1)

  1. 您应该创建一个包含4个字段的数据库表:日期,期间,主题和课堂。
  2. 创建表单,为星期一第一期的“1-1-subject”命名元素,为星期三第5期命名“3-5-subject”。
  3. 迭代post值并将它们保存到db,您可以使用PHP explode函数轻松地将字段名称分开。