I have a MySQL database with a hierarchical genre_id (one letter is the first level, two letters the second level).
This is an example of the database the first item is the genre_id and the second is the genre:
Not exactly what you were looking for, but you might get ideas from it:
Yes it gives me the idea to combine a query with PHP code instead of only use a query.
It is not the most elegant way, but it works.
Someone has a better idea or even a query witch can do the same?
<?php
// Conect to MySQL database and select table
function GenreTree($genre_id)
{
global $genre_id_array;
global $genre_array;
$query = mysql_query("SELECT genre_id, genre FROM table WHERE genre_id LIKE '" . $genre_id . "_' ORDER BY genre");
while ($genre = mysql_fetch_array($query))
{
$genre_id_array[] = $genre['genre_id'];
$genre_array[] = $genre['genre'];
GenreTree($genre['genre_id']);
}
}
$genre_id_array = array();
$genre_array = array();
GenreTree(''); // Starting from root
?>