My orignal database name instead of blog is newssys but I don't see how that matters I have the comments and posts tables and nothing is wrong with them.
posts has
post_id int(6) AI Primary
Post_title varchar255
post_body text
post_user varchar 32
post_date datetime
even changed the collaition to latin_swedish_ci for the ones that had it to match teh tutorials. nothing. I can verify that the test post is in there as well.
here is the function and the code from blog_list.php
function get_posts(){ $sql = "SELECT `posts`.`post_id` AS `id`, `posts`.`post_title` AS `title`, LEFT(`posts`.`post_body`, 512) AS `preview`, `posts`.`post_user` AS `user`, DATE_FORMAT(`posts`.`post_date`, '%d/%m/%y %H:%i:%s') AS `date`, `comments`.`total_comments`, DATE_FORMAT(`comments`.`last_comment`, '%d/%m/%y %H:%i:%s') AS `last_comment` FROM `posts` LEFT JOIN ( SELECT `post_id`, COUNT(`comment_id`) AS `total_comments`, MAX(`comment_date`) AS `last_comment` FROM `comments` GROUP BY `post_id` ) AS `comments` ON `posts`.`post_id` = `comments`.`post_id` ORDER BY `posts`.`post_date` DESC"; $posts = mysql_query($sql); $rows = array(); while (($row = mysql_fetch_assoc($posts)) !==false){ $row[] = array ( 'id' =>$row['id'], 'title' =>$row['title'], 'preview' =>$row['preview'], 'user' =>$row['user'], 'date' =>$row['date'], 'total_comments' =>($row['total_comments'] === null) ? 0 : $row['total_comments'], 'last_comment' =>($row['last_comment'] === null) ? 'never' : $row['last_comment'] ); } return $rows; }
<div> <?php $posts = get_posts(); foreach ($posts as $post){ ?> <h2><?php $post['title']; ?></h2> <h4>By <?php echo $post['user']; ?> on <?php echo $post['date']; ?></h4> <h4>(<?php echo $post['total_comments']; ?>comments, last comment <?php echo $post['last_comment']; ?>)</h4> <hr /> <p><?php echo $post['preview']; ?></p> <?php } ?> </div>