ecshop根目录调用_ecshop列表页 调用二级分类教程
在category.php 最后添加以下函數
/*獲取頂級id*/
function get_parent($value,$id='')
{
if($value!=0)
{
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$value'";
$res = $GLOBALS['db']->getOne($sql);
return get_parent($res,$value);
}
else
{
return $id;
}
}
/*提取二級分類*/
function get_categories($cat_id = 0)
{
if ($cat_id > 0)
{
$parent_id = $cat_id;
}
else
{
$parent_id = 0;
}
/*
判斷當前分類中全是是否是底級分類,
如果是取出底級分類上級分類,
如果不是取當前分類及其下的子分類
*/
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
{
/* 獲取當前分類及其子分類 */
$sql = 'SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, a.is_show,' .
'b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order AS child_order ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
"WHERE a.parent_id = '$parent_id' ORDER BY parent_order ASC, a.cat_id ASC, child_order ASC";
}
else
{
/* 獲取當前分類及其父分類 */
$sql = 'SELECT a.cat_id, a.cat_name, b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order, b.is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id AND b.is_show = 1 ' .
"WHERE b.parent_id = '$parent_id' ORDER BY sort_order ASC";
}
$res = $GLOBALS['db']->getAll($sql);
$cat_arr = array();
foreach ($res AS $row)
{
if ($row['is_show'])
{
$cat_arr[$row['cat_id']]['id'] ? = $row['cat_id'];
$cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
$cat_arr[$row['cat_id']]['url'] ?= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
if ($row['child_id'] != NULL)
{
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['id'] ? = $row['child_id'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['url'] ?= build_uri('category', array('cid' => $row['child_id']), $row['child_name']);
}
}
}
return $cat_arr;
}
總結
以上是生活随笔為你收集整理的ecshop根目录调用_ecshop列表页 调用二级分类教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java整数翻转_java实现整数反转
- 下一篇: 在reader中勾选pdf复选框_Ado