child.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. //获取所有子集的类
  10. class child
  11. {
  12. public function __construct($tb_name)
  13. {
  14. $this->tb_name = $tb_name;
  15. }
  16. private $tb_name;
  17. private $childIds;
  18. private function _getChildIds($pid = '0', $pk_str='id' , $pid_str ='pid')
  19. {
  20. // $childItem_arr = $this->field('id')->where($pid_str."=".$pid)->findAll();
  21. $childItem_arr = $GLOBALS['db']->getAll("select id from ".DB_PREFIX.$this->tb_name." where ".$pid_str."=".$pid);
  22. if($childItem_arr)
  23. {
  24. foreach($childItem_arr as $childItem)
  25. {
  26. $this->childIds[] = $childItem[$pk_str];
  27. $this->_getChildIds($childItem[$pk_str],$pk_str,$pid_str);
  28. }
  29. }
  30. }
  31. public function getChildIds($pid = '0', $pk_str='id' , $pid_str ='pid')
  32. {
  33. $this->childIds = array();
  34. $this->_getChildIds($pid,$pk_str,$pid_str);
  35. return $this->childIds;
  36. }
  37. }
  38. ?>