function getCourseTreeByid($userid, $courseid) { //通过用户id和课程id获取课程目录及学习状态的json串,返回给界面调用 global $mysql; $id = $courseid; $res = $mysql->query("select id,name from coursecategory where courseid=" . $id . " order by id"); //查找courseid下所有的一级目录 while ($arr = $mysql->fetch_array($res)) { //取出一级目录 $arr["open"] = true; $res2 = $mysql->query("select id,name from coursecategory where parentid=" . $arr["id"] . " order by id"); //查找一级目录下的所有二级目录 $num2 = $mysql->num_rows($res2); //一级目录下二级目录的个数 if ($num2 == 0) { //二级目录个数为0,说明该一级目录为叶子节点,下一行while语句为false,开始为其添加课程单元的children $arr["children"] = getCourseUnitsByCategoryid($userid, $arr["id"]); } while ($arr2 = $mysql->fetch_array($res2)) { //存在二级目录,继续按逻辑寻找三级目录 $arr2["open"] = true; $res3 = $mysql->query("select id,name from coursecategory where parentid=" . $arr2["id"] . " order by id"); $num3 = $mysql->num_rows($res3); if ($num3 == 0) { $arr2["children"] = getCourseUnitsByCategoryid($userid, $arr2["id"]); } while ($arr3 = $mysql->fetch_array($res3)) { $arr3["open"] = true; $res4 = $mysql->query("select id,name from coursecategory where parentid=" . $arr3["id"] . " order by id"); $num4 = $mysql->num_rows($res4); if ($num4 == 0) { $arr3["children"] = getCourseUnitsByCategoryid($userid, $arr3["id"]); } while ($arr4 = $mysql->fetch_array($res4)) { $arr4["open"] = true; $res5 = $mysql->query("select id,name from coursecategory where parentid=" . $arr4["id"] . " order by id"); $num5 = $mysql->num_rows($res5); if ($num5 == 0) { $arr4["children"] = getCourseUnitsByCategoryid($userid, $arr4["id"]); } while ($arr5 = $mysql->fetch_array($res5)) { $arr5["open"] = true; $res6 = $mysql->query("select id,name from coursecategory where parentid=" . $arr5["id"] . " order by id"); $num6 = $mysql->num_rows($res6); if ($num6 == 0) { $arr5["children"] = getCourseUnitsByCategoryid($userid, $arr5["id"]); } while ($arr6 = $mysql->fetch_array($res6)) { $arr6["open"] = true; $res7 = $mysql->query("select id,name from coursecategory where parentid=" . $arr6["id"] . " order by id"); $num7 = $mysql->num_rows($res7); if ($num7 == 0) { $arr6["children"] = getCourseUnitsByCategoryid($userid, $arr6["id"]); } while ($arr7 = $mysql->fetch_array($res7)) { $arr7["open"] = true; $arr7["name"] = $arr7["name"]; $arr7["status"] = ""; $arr7["totaltime"] = ""; $arr7["score"] = ""; $arr7["viewcount"] = ""; $arr7["lasttime"] = ""; $arr7["remark"] = ""; $arr7["itemurl"] = ""; $arr6["children"][] = $arr7; } $arr6["name"] = $arr6["name"]; $arr6["status"] = ""; $arr6["totaltime"] = ""; $arr6["score"] = ""; $arr6["viewcount"] = ""; $arr6["lasttime"] = ""; $arr6["remark"] = ""; $arr6["itemurl"] = ""; $arr5["children"][] = $arr6; } $arr5["name"] = $arr5["name"]; $arr5["status"] = ""; $arr5["totaltime"] = ""; $arr5["score"] = ""; $arr5["viewcount"] = ""; $arr5["lasttime"] = ""; $arr5["remark"] = ""; $arr5["itemurl"] = ""; $arr4["children"][] = $arr5; } $arr4["name"] = $arr4["name"]; $arr4["status"] = ""; $arr4["totaltime"] = ""; $arr4["score"] = ""; $arr4["viewcount"] = ""; $arr4["lasttime"] = ""; $arr4["remark"] = ""; $arr4["itemurl"] = ""; $arr3["children"][] = $arr4; } $arr3["name"] = $arr3["name"]; $arr3["status"] = ""; $arr3["totaltime"] = ""; $arr3["score"] = ""; $arr3["viewcount"] = ""; $arr3["lasttime"] = ""; $arr3["remark"] = ""; $arr3["itemurl"] = ""; $arr2["children"][] = $arr3; } $arr2["name"] = $arr2["name"]; $arr2["status"] = ""; $arr2["totaltime"] = ""; $arr2["score"] = ""; $arr2["viewcount"] = ""; $arr2["lasttime"] = ""; $arr2["remark"] = ""; $arr2["itemurl"] = ""; $arr["children"][] = $arr2; } $arr["name"] = $arr["name"]; $arr["status"] = ""; $arr["totaltime"] = ""; $arr["score"] = ""; $arr["viewcount"] = ""; $arr["lasttime"] = ""; $arr["remark"] = ""; $arr["itemurl"] = ""; $node["children"][] = $arr; } $courseinfo = getCourseinfoById($id); $node["name"] = $courseinfo["title"]; $node["status"] = ""; $node["totaltime"] = ""; $node["score"] = ""; $node["viewcount"] = ""; $node["lasttime"] = ""; $node["remark"] = ""; $node["itemurl"] = ""; //@$nodes = "children:".json_encode($node["children"],JSON_UNESCAPED_UNICODE); //return json_encode($node,JSON_UNESCAPED_UNICODE); return json_encode($node, JSON_UNESCAPED_UNICODE); }
<div class="clear"> </div> <div id="main"> <!-- start of #main wrapper for #content and #menu divs --> <!-- Begin Of script Output --> <div id="content" class="maxcontent"> <div id="content_with_menu"> <div id="container"> <div class="info">添加/编辑课程</div> <div class="wrap"> <?php $id = isset($_GET["id"]) ? $_GET["id"] : 0; $title = $startTime = $endTime = $yes = $no = $type1 = $type0 = ""; $alwaysUpdate = 1; $type = 1; if ($id) { $courseInfo = getCourseinfoById($id); $title = $courseInfo["title"]; $startTime = $courseInfo["starttime"]; $endTime = $courseInfo["endtime"]; $alwaysUpdate = $courseInfo["alwaysupdate"]; $type = $courseInfo["type"]; } if ($alwaysUpdate) { $yes = "checked"; } else { $no = "checked"; } if ($type) { $type1 = "checked"; } else { $type0 = "checked";