Dunque, con un po' di codice da manuale e per nulla raffinato, ho ottenuta quanto nell'immagine allegata.
Ecco il codice:
Codice PHP:
$get_data = "SELECT * FROM menu WHERE struttura NOT LIKE '%>%'";
$result = mysql_query($get_data, $conn);
while($row = mysql_fetch_array($result)){
print $row["struttura"] . "
";
$get_data2 = "SELECT * FROM menu WHERE struttura LIKE '%" . $row["struttura"] . ">%' AND struttura NOT LIKE '%>%>%' ORDER BY struttura";
$result2 = mysql_query($get_data2, $conn);
if(mysql_num_rows($result2) > 0){
while($row2 = mysql_fetch_array($result2)){
print "" . substr($row2["struttura"], strrpos($row2["struttura"], ">")+1) . "
";
$get_data3 = "SELECT * FROM menu WHERE struttura LIKE '%" . substr($row2["struttura"], strpos($row2["struttura"], ">")+1) . ">%' ORDER BY struttura";
$result3 = mysql_query($get_data3, $conn);
if(mysql_num_rows($result3) > 0){
while($row3 = mysql_fetch_array($result3)){
print "" . substr($row3["struttura"], strrpos($row3["struttura"], ">")+1) . "
";
}
}
}
}
}
Si presuppone che la struttura delle categorie non scenda oltre il terzo livello.
Ma come ci fosse la necessità di andare oltre? O comunque non sapere a priori che livello di profondità si deve andare?