datetime error for SQL statement in blog tutorial
Posted: Tue Dec 06, 2011 7:03 pm
Hello,
My name is Gene and I have been following the blog tutorials on YouTube in BetterPHP. However when I write the query statement for the function "get_posts", there is an error in my phpmyadmin that says: "#1054 - Unknown column 'd-m-Y H:i:s' in 'field list' " Please help..here is the sql statement listed from the tutorial. Thanks!! :
[syntax=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"[/syntax]
My name is Gene and I have been following the blog tutorials on YouTube in BetterPHP. However when I write the query statement for the function "get_posts", there is an error in my phpmyadmin that says: "#1054 - Unknown column 'd-m-Y H:i:s' in 'field list' " Please help..here is the sql statement listed from the tutorial. Thanks!! :
[syntax=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"[/syntax]