//获取所有下线 function get_all_heeler($user_id,$user_rank = 0){ $user_id_array = $user_id; while (true) { if (!empty($user_rank)) { $judge = "AND user_rank =".$user_rank; } //取得所有直接下线 并累计到数组里面 $row = $GLOBALS['db']->getAll("SELECT user_name,user_id,user_rank FROM " . $GLOBALS['ecs']->table('users') . " WHERE parent_id in (" . $user_id_array . ")" . $judge); if (!empty($row)) { $user_id_array = null; foreach ($row as $key => $value) { $user_id_array .= $value['user_id'] . ","; //查询还有没有下级 $is_heeler .= $GLOBALS['db']->getOne("SELECT user_id FROM " . $GLOBALS['ecs']->table('users') . " WHERE parent_id = ".$value['user_id']. $judge); } } //判断还有没有下级如果有则继续循环 否则退出循环 if (empty($is_heeler)) { break; } $is_heeler = null; //累计结果 $result .= $user_id_array; //去掉结尾的逗号,为下次查询做准备 if (substr($user_id_array, -1) == ',') { $user_id_array = substr($user_id_array,0, strlen($user_id_array)-1); } } //去掉结尾的逗号 $result .= substr($user_id_array,0, strlen($user_id_array)-1); return $result; }