function getall_producttype_parent_id($table, &$typeid_str, $parentid) { //$typeList = array(); $result = $GLOBALS['db']->query("SELECT * FROM {$table} WHERE parent_id={$parentid}"); while ($row = $GLOBALS['db']->fetch($result)) { $typeid_str .= ',' . $row['id']; getall_producttype_parent_id($table, $typeid_str, $row['id']); } }
<?php require_once 'inc.php'; $table = 'cn_along'; $action = empty($_GET["action"]) ? '' : $_GET["action"]; $tpid = empty($_GET["type_id"]) ? '' : $_GET["type_id"]; $tpid2 = ''; $list_mokuai = alla2("cn_mokuai", "", "order by id asc", '*'); $smarty->assign('list_mokuai', $list_mokuai); if ($action == "") { $where = ''; #产品分类递归 if (!empty($_GET['type_id'])) { $typeid_str = ''; getall_producttype_parent_id("cn_along_type", $typeid_str, $_GET['type_id']); $typeid_str = $_GET['type_id'] . $typeid_str; $where = " AND type_id in(" . $typeid_str . ")"; } $where .= @$_GET['keyword'] != '' ? " AND (title LIKE '%" . @$_GET['keyword'] . "%')" : ''; $order = ' ORDER BY sort asc,id DESC'; $page_size = 20; $current_page = !@$_GET['p'] ? 1 : @$_GET['p']; $nums = $db->query_count($table, $where); $productList = ''; $result = $db->query_page_list($table, $page_size, $current_page, $order, $where); while ($row = $db->fetch($result)) { $result2 = $db->query('SELECT name FROM cn_along_type WHERE id=' . $row['type_id']); $type = $db->fetch($result2); $productList[] = array('id' => $row['id'], 'title' => $row['title'], 'type_name' => $type['name'], 'time' => date('Y-m-d', $row['time']), 'sort' => $row['sort'], 'guishu' => $row['guishu']); } $pager = new Pager($page_size, $nums, $current_page, 8);
<?php require_once 'inc.php'; $table = 'cn_course'; $smarty->assign('table', $table); $action = empty($_GET["action"]) ? '' : $_GET["action"]; if ($action == "") { $where = ''; #产品分类递归 if (!empty($_GET['type_id'])) { $typeid_str = ''; getall_producttype_parent_id("cn_course_type", $typeid_str, $_GET['type_id']); $typeid_str = $_GET['type_id'] . $typeid_str; $where = " AND type_id in(" . $typeid_str . ")"; } $tid = empty($_GET["tid"]) ? '' : $_GET["tid"]; $tid2 = empty($_GET["type_id"]) ? '' : $_GET["type_id"]; if ($tid2 != '' && $tid == '') { $tid = $tid2; } $smarty->assign('tid', $tid); $where .= @$_GET['keyword'] != '' ? " AND (title LIKE '%" . @$_GET['keyword'] . "%')" : ''; $order = ' ORDER BY sort asc,time DESC'; $page_size = 20; $current_page = !@$_GET['p'] ? 1 : @$_GET['p']; $nums = $db->query_count($table, $where); $productList = ''; $result = $db->query_page_list($table, $page_size, $current_page, $order, $where); while ($row = $db->fetch($result)) { $result2 = $db->query('SELECT name FROM cn_course_type WHERE id=' . $row['type_id']); $type = $db->fetch($result2);