求高手赐教,怎样在商品子分类下调用上级分类的产品

2016-07-07 15:02 来源:www.chinab4c.com 作者:ecshop专家

求高手赐教,怎样在商品子分类下调用上级分类的产品

回答:
你取得父类接点的ID.然后通过ID取得商品 

搜索的时候加上父级ID就可以啊。

  1. function get_child_tree($tree_id)
  2. {


  3. $three_arr = array();
  4. $sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$tree_id' AND is_show = 1 ";
  5. $cat_name = $GLOBALS['db']->getOne($sql);

  6. $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";

  7. if ($GLOBALS['db']->getOne($sql))
  8. {
  9. $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
  10. 'FROM ' . $GLOBALS['ecs']->table('category') .
  11. "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
  12. $res = $GLOBALS['db']->getAll($child_sql);
  13. foreach ($res AS $row)
  14. {
  15. if ($row['is_show'])

  16. $three_arr[$row['cat_id']]['id']= $row['cat_id'];
  17. $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
  18. $three_arr[$row['cat_id']]['url']= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

  19. }
  20. }
  21. else {
  22. // echo "sdf";

  23. $sql = "SELECT parent_id,cat_name FROM " . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$tree_id' AND is_show = 1 ";

  24. $rows = $GLOBALS['db']->getRow($sql);
  25. // print_r($rows);exit;
  26. $parent_id = $rows['parent_id'];

  27. $sql1 = "SELECT cat_name FROM " . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$parent_id' AND is_show = 1 ";

  28. $cat_name = $GLOBALS['db']->getOne($sql1);
  29. //echo $cat_name;exit;
  30. $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
  31. 'FROM ' . $GLOBALS['ecs']->table('category') .
  32. "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
  33. $res = $GLOBALS['db']->getAll($child_sql);
  34. foreach ($res AS $row)
  35. {
  36. if ($row['is_show'])

  37. $three_arr[$row['cat_id']]['id']= $row['cat_id'];
  38. $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
  39. $three_arr[$row['cat_id']]['url']= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
  40. }
  41. }

  42. //$arr['cat_list'] = $three_arr;
  43. //$arr['cat_name'] = $cat_name;
  44. //print_r($three_arr);exit;
  45. return $three_arr;
  46. }
复制代码
能否看懂这个函数