Mam taki kod, wszystko jest dobrze dopóki nie ma bardziej skomplikowanej hierarchii stron.
<?php
$list = '<select name="page">';
for($i = 0; $i < count($this->PageList); $i++) {
$checked = ($this->PageList[$i]['page_id'] == $id) ? 'selected' : '';
if($this->PageList[$i]['page_parent'] == 0)
{
$list .= '<option value="' . $this->PageList[$i]['page_id'] . '" ' . $checked . '>' . $this->PageList[$i]['page_title'] . '</option>';
for($j = 0; $j < count($this->PageList); $j++) {
if($this->PageList[$j]['page_parent'] == $this->PageList[$i]['page_id'])
{
$par = 1;
$list .= '<option value="' . $this->PageList[$j]['page_id'] . '" ' . $checked . '>- ' . $this->PageList[$j]['page_title'] . '</option>';
for($a = 0; $a < count($this->PageList); $a++) {
if($this->PageList[$a]['page_parent'] == $this->PageList[$j]['page_id'])
{
$par = $par+1;
}
}
if($par > 1)
{
$tag = '-';
for($r = 0; $r < count($this->PageList); $r++) {
if($this->PageList[$j]['page_id'] == $this->PageList[$r]['page_parent'])
{
$tag .= '-';
$list .= '<option value="' . $this->PageList[$r]['page_id'] . '" ' . $checked . '>' . $tag . ' '. $this->PageList[$r]['page_title'] . '</option>';
}
}
}
}
}
}
}
if(!$parent)
{
$list .= '<option value="0">Nigdzie nie nalezy</option>';
}
$list .= '</select>';
?>
Wszystko jest ok na takim poziomie:
Strona główna
- podstrona 1
-- podstrona 2
a jak już daje 3 i 4 podstronę to pokazuje tak samo:
Strona główna
- podstrona 1
-- podstrona 2
Proszę o pomoc bo walczę z tym od wczoraj i się zamotałem