我有一个数据库结构如下:
tbl_topic tbl_chapter
-pk id (AutoIncrement) -pk id
-fk parent_id (references itself) -chapter_name
-fk chapter_id (references tbl_chapter)
-name
-description
-teaching_hours
-teaching_periods
有主题的章节,章节有主题(主题可能有子主题等)。首先,我需要设计一个表单,用户可以在其中为特定章节添加主题,如下所示:
Chapter 1: Science: (Add topic +)
1.Topic: Name:_____ Description: _____ Hours _____(Add topic +)
Topic Name:_____ Description: _____ Hours _____(Add topic +)
Topic Name:_____ Description: _____ Hours _____(Add topic +)
2.Topic: Name:_____ Description: _____ Hours _____(Add topic +)
Topic Name:_____ Description: _____ Hours _____(Add topic +)
我只需要一个算法或步骤或有关如何分层插入元素并在 php 或 jsp 等语言中获取元素层次结构的提示。另外,如果这个数据库设计不好,请告诉我一个更好的方法来构建它。
这是我在我的项目中做什么
处理主页上的新闻对象。新闻将以 json 字符串的形式来自数据库
然后
if(!(news ==null)){
for(var i=0; i < news.list.length; i++){
$(news.list[i]).attr("clientid" ,i);
var listItemDiv = $("<li id="+news.list[i].clientid+"><h3>"+news.list[i].title+"</h3><span class=date>Department:"+getDepartmentName(news.list[i])+" "+getSubDepartMentName(news.list[i])+"<span><span class=date>Opening Date:"+news.list[i].startDate+"<span><a target='_blank' style='float:right' href='docdetails?docid="+news.list[i].id+" ' >Read More..</a></li></br>");
$('#newsitems').append($(listItemDiv));
}
在您的情况下,您有另一个循环来迭代chapter.list object
祝你好运。