简体   繁体   English

使用PHP从MySQL数据库填充HTML表

[英]Populating HTML table with data from MySQL database using PHP

I have a table with structure as: 我有一个表,其结构为:

CREATE TABLE `lectures` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(255) NOT NULL,
`semester` varchar(255) NOT NULL,
`course_no` varchar(255) NOT NULL,
`course_title` varchar(255) NOT NULL,
`faculty_name` varchar(216) NOT NULL,
`upload_file` varchar(255) NOT NULL,
`dateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1

Now the scenario is, I have 3 things; 现在的场景是,我有三件事: semester, course and lecturer. 学期,课程和讲师。 There can be more than one semesters, each semester can have multiple courses and each course can be have many lecturers. 一个学期可以不止一个学期,每个学期可以有多个课程,每个课程可以有很多讲师。 Above DB table have all the data in it. DB表上方具有所有数据。 I want to populate data in HTML table whose structure can be as follows. 我想在HTML表中填充数据,其结构可以如下。 图片所示结构

I want to populate data in above pic format. 我想以上述图片格式填充数据。 I can't figure out how to do that. 我不知道该怎么做。

Any help appreciated. 任何帮助表示赞赏。

When you write the query, add an additional column say 'CourseClass'. 当您编写查询时,请添加其他列,例如“ CourseClass”。 Make the CourseClass equal to the name of the course. 使CourseClass等于课程名称。

Once you have a table with your data and the additional column, you can write jquery or js to merge the rows with similar values. 一旦有了包含数据和附加列的表,就可以编写jquery或js以合并具有相似值的行。

At the front-end, simply hide the extra column you added. 在前端,只需隐藏您添加的额外列。

Alternatively, you can look this up. 或者,您可以查找此内容。 The person is trying to achieve something similar - html table span if the data is same 该人正在尝试实现类似的目标- 如果数据相同,则html表跨度

There is a JSFiddle link in there too. 那里也有一个JSFiddle链接。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM