multilevel ul with PHP
Posted: Wed Oct 07, 2009 8:36 am
hi, I'm pretty new to PHP and I need help with multilevel unordered list.
I retrieve data from 2 tables of database and get an array which I need to tranform somehow into multilevel unordered list:
That's the piece of code I have,and as a result of it I get number of arrays like:
I need to build a function so that in the result of it I get a list like the following:
1Fiction
------1 Karmen
------2 Thunder
2Adventure
------3 Forest and so on...
Can anyone help me with a piece of code how to achieve this result?
I retrieve data from 2 tables of database and get an array which I need to tranform somehow into multilevel unordered list:
Code: Select all
try
{
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'SELECT BookGroups.GroupID, GroupName, BookID, BookName FROM BookGroups, BookEntries WHERE BookGroups.GroupID = BookEntries.GroupID';
$stmt = $dbh->prepare($sql);
$stmt->execute();
while ($item=$stmt->fetch(PDO::FETCH_ASSOC)) {
print_r($item);} ....Code: Select all
Array
(
[GroupID] => 1
[GroupName] => Fiction
[BookID] => 1
[BookName] => Karmen
)
(
[GroupID] => 1
[GroupName] => Fiction
[BookID] => 2
[BookName] => Thunder
)1Fiction
------1 Karmen
------2 Thunder
2Adventure
------3 Forest and so on...
Can anyone help me with a piece of code how to achieve this result?