$sqlcount = "SELECT count(*) from " . DB::table('content_cate') . " WHERE isdelete=0 " . $wheresql; $pagetotal = DB::result_first($sqlcount); $sql = "SELECT info_cateid,info_catepid,title from " . DB::table('content_cate') . " WHERE isdelete=0 " . $wheresql . " ORDER BY info_cateid DESC LIMIT " . $pagestart . "," . $numPerPage; $page_array = DB::fetch_all($sql); include template('admin/info/info_cate'); break; default: //DEBUG 查询并返回信息链接 $page_array = array(); $sqlcount = $sql = $wheresql = $title_keyword = $pageNum = $numPerPage = ''; $title_keyword = isset($_REQUEST['title_keyword']) ? $_REQUEST['title_keyword'] : ''; $pageNum = isset($_REQUEST['pageNum']) ? $_REQUEST['pageNum'] : 1; $numPerPage = isset($_REQUEST['numPerPage']) ? $_REQUEST['numPerPage'] : 10; $pagestart = ($pageNum - 1) * $numPerPage; if ($title_keyword) { $wheresql .= " AND title LIKE '%" . $title_keyword . "%'"; } $sqlcount = "SELECT count(*) from " . DB::table('content_cate') . " WHERE isdelete=0 " . $wheresql; $pagetotal = DB::result_first($sqlcount); $sql = "SELECT info_cateid,info_catepid,title from " . DB::table('content_cate') . " WHERE isdelete=0 " . $wheresql . " ORDER BY info_cateid DESC LIMIT " . $pagestart . "," . $numPerPage; $page_array = DB::fetch_all($sql); //DEBUG 获取分类树形菜单 START $cate_results_tmp = $cate_results = array(); $sql = "SELECT info_cateid, title, info_catepid from " . DB::table('content_cate') . " WHERE isdelete=0 AND info_catepid = 0 ORDER BY info_cateid ASC"; $cate_results_tmp = DB::fetch_all($sql); $cate_results_tree = dbarr2tree($cate_results_tmp); $tree2htmlul_infosearch = tree2htmlul_catesearch($cate_results_tree, 'tree treeFolder'); //DEBUG 获取分类树形菜单 END include template('admin/info/info_cate_multi'); break; }
function dbarr2tree($tree, $rootId = 0) { $return = array(); foreach ($tree as $leaf) { if ($leaf['info_catepid'] == $rootId) { foreach ($tree as $subleaf) { if ($subleaf['info_catepid'] == $leaf['info_cateid']) { $leaf['children'] = dbarr2tree($tree, $leaf['info_cateid']); break; } } $return[] = $leaf; } } return $return; }