setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); # creating the statement $sql = "SELECT brand_id from preferred where user_id=:user_id"; $sth = $dbh->prepare($sql); $sth->setFetchMode(PDO::FETCH_OBJ); $sth->execute(array(':user_id' => get_user_id())); $preferred = $sth->fetchAll(); foreach ($preferred as $brand) { $bs = new BrandService(); $brands[] = $bs->getBrandByID($brand->brand_id); $bs = null; } $brandMap = array(); foreach ($brands as $brand) { $geometryService = new GeometryService(); $geometries = $geometryService->getAllGeometriesByBrand($brand->id); foreach ($geometries as $geometry) { $modelService = new ModelService(); $brandMap[$brand->name][$geometry->name]['models'] = $modelService->getAllModelsByGeometry($geometry->id); $frameService = new FrameService(); $frames = $frameService->getAllFramesByGeometry($geometry->id); if ($frames === null) { header('location:add_frame.php');} foreach ($frames as $frame) { $brandMap[$brand->name][$geometry->name]['geometries'][] = $frame; } } } $smarty = new Smarty; $smarty->assign('brandMap', $brandMap); $smarty->display('views/index.tpl'); } catch(PDOException $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } ?>