Alright so I have created a blog from scratch and mistakenly started to write it with mysql_ statements so I have gone back and rewritten it with PDO statements. I have now encountered a problem with displaying my blog post from my database.
<?php
include 'includes.php';
echo '<h3>-----------------------------------------------------</h3>';
$blogIndex = 'SELECT * FROM blog_post ORDER BY date_posted DESC';
$blogIndexstmt = $DBH->prepare($blogIndex);
$blogIndexRows = $blogIndexstmt->fetchAll();
if(!$blogIndexRows) {
echo 'No Post Yet.';
}
else {
while($blogIndexRows->nextRowset()) {
echo '<h2>' . $row['title'] . '</h2>';
$datePosted = $row['date_posted'];
echo '<p>' . gmdate('F j, Y, g:i a', $datePosted) . '</p>';
$body = substr($row['post'], 0, 300);
echo nl2br($body) . '...<br/>';
echo '<a href="post_view.php?id=' . $row['id']. '">Read More</a> | ';
echo '<a href="post_view.php?id=' . $row['id'] . '#comments">' .
$row['num_comments'] . ' comments</a>';
echo '<hr/>';
}
}
$DBH = null;
echo <<<HTML
<a href="post_add.php">+ New Post</a>
HTML;
?>
It does not display anything, not even an error code. I was able to do it correctly with the mysql_ statement but I really want to learn how to do this correctly. I am just looking for a nudge in the right direction, you do now have to code it for me. Thanks for you help in advance!