public static function recursive($table, $colums = array('id' => 'id', 'parent' => 'parentid', 'text' => 'name'), $where, $parentid = 0, $level = 0, &$result) { $db = JFactory::getDbo(); if (!$result) { $result = array(); } //khoi tao 1 array co ten la arr //var_dump($colums['parentid']);exit; $cols = array_values($colums); //var_dump($colums['parentid'].' = '.$parentid);exit; $query = $db->getQuery(true)->select($cols)->from($table); if ('NULL' == strtoupper($parentid)) { $query->where($colums['parent'] . ' IS NULL '); } else { $query->where($colums['parent'] . ' = ' . $parentid); } if ($where != null && is_array($where)) { $query->where($where); } $db->setQuery($query); $rows = $db->loadAssocList(); for ($i = 0; $i < count($rows); $i++) { $row = $rows[$i]; $result[] = array('id' => $row['id'], 'text' => $row[$colums['text']], 'parent' => $row[$colums['parent']] == null ? '#' : $row[$colums['parent']], 'level' => $level); $result = ThontoHelper::recursive($table, $colums, $where, $row[$colums['id']], $level + 1, $result); } return $result; }