Witam, mam problem z jedną rzeczą a dokładnie:
function tree()
{
$sql = $this->pdo->query("SELECT * FROM `plugins` ORDER BY `ptitle`");
$tree[] = array('section_id' => 2, 'section_parent_id' => '1', 'section_name' => 'Użytkownicy', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1
); $tree[] = array('section_id' => 3, 'section_parent_id' => '1', 'section_name' => 'System', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1
); $tree[] = array('section_id' => 4, 'section_parent_id' => '1', 'section_name' => 'Zawartość', 'section_module' => '#', 'section_plugin' => '', 'depth' => 1
);
$i = 4;
while($r = $sql->fetch(PDO::FETCH_OBJ))
{
$tree[] = array('section_id' => $i, 'section_parent_id' => $r->prights+1, 'section_name' => $r->ptitle, 'section_module' => $r->plink, 'section_plugin' => $r->pinstall, 'depth' => 2
); $i++;
}
return $tree;
}
Wyświetla mi tablicę w takiej postaci:
Array
(
[0] => Array
(
[section_id] => 2
[section_parent_id] => 1
[section_name] => Użytkownicy
[section_module] => #
[section_plugin] =>
[depth] => 1
)
[1] => Array
(
[section_id] => 3
[section_parent_id] => 1
[section_name] => System
[section_module] => #
[section_plugin] =>
[depth] => 1
)
[2] => Array
(
[section_id] => 4
[section_parent_id] => 1
[section_name] => Zawartość
[section_module] => #
[section_plugin] =>
[depth] => 1
)
[3] => Array
(
[section_id] => 4
[section_parent_id] => 2
[section_name] => Administratorzy
[section_module] => administrators
[section_plugin] => 0
[depth] => 2
)
[4] => Array
(
[section_id] => 5
[section_parent_id] => 3
[section_name] => Backup
[section_module] => backup
[section_plugin] => 0
[depth] => 2
)
[5] => Array
(
[section_id] => 6
[section_parent_id] => 4
[section_name] => FAQ
[section_module] => faq
[section_plugin] => 1
[depth] => 2
)
[6] => Array
(
[section_id] => 7
[section_parent_id] => 4
[section_name] => Formularz kontaktowy
[section_module] => contact
[section_plugin] => 1
[depth] => 2
)
)
Pierwsze trzy elementy powinny być wstawione przed tablicę, która zawiera wartość section_parent_id równą section_id. Niestety nie wiem jaką funkcję zastosować, aby połączyć tablicę, tak aby te 3 elementy znalazły się przed pierwszym elementem swojej podkategorii.
Mógłbym to zrobić innym sposobem, jednak jestem ciekaw czy jest jakaś funkcja, która pozwoli to zrobić szybciej
Ten post edytował potreb 22.03.2011, 11:26:39