Blog problem with "DATE_FORMAT"

Post here is you are having problems with any of the tutorials.
Post Reply
xatron
Posts: 3
Joined: Sun Oct 16, 2011 10:28 pm

Blog problem with "DATE_FORMAT"

Post by xatron »

Hello.
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`.`posts_date`, `%d/%m/%Y %H:%i:%s`) AS `date`,
					`comments`.`total_comments`,
					DATE_FORMAT(`comments`,`last_comment`, `%d/%m/%Y %H:%i:%s`) AS `date`) AS `lastcomment`
				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
and i get this error. #1582 - Incorrect parameter count in the call to native function 'DATE_FORMAT'
What should i do?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Blog problem with "DATE_FORMAT"

Post by jacek »

one of the . between your table and column names is a ,
Image
xatron
Posts: 3
Joined: Sun Oct 16, 2011 10:28 pm

Re: Blog problem with "DATE_FORMAT"

Post by xatron »

What?
Where do i missed something?
icey2k
Posts: 16
Joined: Mon Jul 04, 2011 4:26 pm

Re: Blog problem with "DATE_FORMAT"

Post by icey2k »

xatron wrote:What?
Where do i missed something?
 DATE_FORMAT(`comments`,`last_comment`, `%d/%m/%Y %H:%i:%s`) AS `date`) AS `lastcomment`
xatron
Posts: 3
Joined: Sun Oct 16, 2011 10:28 pm

Re: Blog problem with "DATE_FORMAT"

Post by xatron »

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'.'posts_date', '%d/%m/%Y %H:%i:%s') AS 'date',
					'comments'.'total_comments',
					DATE_FORMAT('comments'.'last_comment', '%d/%m/%Y %H:%i:%s') AS 'date', AS 'lastcomment'
				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
064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.'post_id' AS 'id', 'posts'.'post_title' AS 'title', LEFT('posts'.'pos' at line 2
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Blog problem with "DATE_FORMAT"

Post by jacek »

Your column and table names need to have ` around them not '
Image
Post Reply