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?