HyperText
14-11-2004, 14:11
Ho il seguente codice:
$Sql->select("list", "*", "prefix_cat_for");
while ( $list = $Sql->assoc("list") )
{
$this->list_out[ $list['id'] ] = Array(
'id' => $list['id'],
'parent' => $list['parent'],
'name' => $list['name'],
'f_description' => $list['f_description'],
);
if ( $list['parent'] > 0 )
{
$this->sons[ $list['parent'] ][ $list['id'] ] = $list;
}
else
{
$this->fathers[ $list['id'] ] = $list;
}
}
foreach ( $this->list_out as $cat_id => $cat_data )
{
foreach ( $this->fathers as $for_id => $for_data )
{
if ( $for_data['parent'] == $cat_id )
{
$this->output_list .= $this->prova($for_data);
}
}
if ( $cat_data['parent'] == -1 && $for_data['parent'] == $cat_data['id'] )
{
echo "> ".$cat_data['name']."<br />".$this->output_list."<br />";
}
}
In pratica estraggo i dati di una tabella che contiene i dati delle varie categorie e sotto-categorie (forum).
Ora mettiamo che i dati sono:
id | parent | name
0 | -1 | Categoria 1
1 | 0 | Forum 1
2 | -1 | Categoria 2
3 | 0 | Forum 2
4 | 2 | Forum 3
5 | 0 | Forum 4
Quel codice mi stampa:
> Categoria 1
>> Forum 1
>> Forum 2
>> Forum 4
Il quale è esatto, ma sotto dovrebbe restituirmi anche:
> Categoria 2
>> Forum 3
E invece non lo fa.
Grazie
:ciauz:
$Sql->select("list", "*", "prefix_cat_for");
while ( $list = $Sql->assoc("list") )
{
$this->list_out[ $list['id'] ] = Array(
'id' => $list['id'],
'parent' => $list['parent'],
'name' => $list['name'],
'f_description' => $list['f_description'],
);
if ( $list['parent'] > 0 )
{
$this->sons[ $list['parent'] ][ $list['id'] ] = $list;
}
else
{
$this->fathers[ $list['id'] ] = $list;
}
}
foreach ( $this->list_out as $cat_id => $cat_data )
{
foreach ( $this->fathers as $for_id => $for_data )
{
if ( $for_data['parent'] == $cat_id )
{
$this->output_list .= $this->prova($for_data);
}
}
if ( $cat_data['parent'] == -1 && $for_data['parent'] == $cat_data['id'] )
{
echo "> ".$cat_data['name']."<br />".$this->output_list."<br />";
}
}
In pratica estraggo i dati di una tabella che contiene i dati delle varie categorie e sotto-categorie (forum).
Ora mettiamo che i dati sono:
id | parent | name
0 | -1 | Categoria 1
1 | 0 | Forum 1
2 | -1 | Categoria 2
3 | 0 | Forum 2
4 | 2 | Forum 3
5 | 0 | Forum 4
Quel codice mi stampa:
> Categoria 1
>> Forum 1
>> Forum 2
>> Forum 4
Il quale è esatto, ma sotto dovrebbe restituirmi anche:
> Categoria 2
>> Forum 3
E invece non lo fa.
Grazie
:ciauz: