print_r($post)
does display the associative array but when I try to get a specific index, the index is undefined. What am I doing wrong?
<?php
$title = 'Post Detail';
include('_top.php');
require_once(__DIR__ . '/dao/PostDAO.php');
//instantie van Klasse
$postDAO = new PostDAO();
//methode oproepen
$post = $postDAO->getPostById();
echo "<pre>";
print_r($post);
echo "</pre>";
?>
<article>
<header><h2><?php echo $post['title']; ?></h2></header>
<?php echo $post['body']; ?>
</article>
<section class="comments">
<header><h3>Comments</h3></header>
<?php
if (empty($comments)) {
echo "<p>There are no comments for this post.</p>";
} else {
echo "<ol>";
foreach( $comments as $comment ){
echo "<li>";
echo $comment['text'];
echo "</li>";
}
echo "</ol>";
}
?>
</section>
<?php include('_bottom.php');?>
I get this error:
Notice: Undefined index: title in /Applications/MAMP/htdocs/back-end/Lesweek 5/labo/startbestanden/14-exercise/post-detail.php on line 14
Notice: Undefined index: body in /Applications/MAMP/htdocs/back-end/Lesweek 5/labo/startbestanden/14-exercise/post-detail.php on line 15
Comments
There are no comments for this post.