index.dwt里代码
index.php代码
//得到分类下的品牌 function get_brands1($url = 0, $app = 'brand') { preg_match("/\d+/i",$url,$matches); $cat = $matches[0]; $children = ($cat > 0) ? ' AND ' . get_children($cat) : ''; $sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, b.brand_desc, COUNT(*) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag ". "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ". $GLOBALS['ecs']->table('goods') . " AS g ". "WHERE g.brand_id = b.brand_id $children AND is_show = 1 " . " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ". "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC"; $row = $GLOBALS['db']->getAll($sql); foreach ($row AS $key => $val) { $row[$key]['url'] = build_uri($app, array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']); $row[$key]['brand_desc'] = htmlspecialchars($val['brand_desc'],ENT_QUOTES); } return $row; } //*** 调用商品分类指定分类下级分类 function get_parent_id_tree($parent_id) { $three_c_arr = array(); $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 "; if ($GLOBALS['db']->getOne($sql)) { $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC"; $res = $GLOBALS['db']->getAll($child_sql); foreach ($res AS $row) { if ($row['is_show']) $three_c_arr[$row['cat_id']]['id'] = $row['cat_id']; $three_c_arr[$row['cat_id']]['name'] = $row['cat_name']; $three_c_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); } } return $three_c_arr; }
这里有个写法 foreach from里面可以写函数 函数里还可以写变量。。。。