Page 1 of 1

blog a Tutorial by jacek

Posted: Thu Sep 20, 2012 12:16 pm
by i3c
hello,

seems i got a error and i don't know where or what it can be.
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){

$rows[] = 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;

}
the error stops on: while (($row = mysql_fetch_assoc($posts)) !== false){

the error contains:
Image

any help please.
thanks

Re: blog a Tutorial by jacek

Posted: Thu Sep 20, 2012 1:02 pm
by EcazS
After your query add,
echo mysql_error();
It will give you a more detailed description of the error.

Re: blog a Tutorial by jacek

Posted: Thu Sep 20, 2012 1:08 pm
by i3c
thanks for the fast reply.

okay got the error:

Incorrect parameter count in Call to native function 'DATE_FORMAT'

any idea how to fix this?

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 6:31 am
by Helx
You can only have 2 parameters in MySQL's DATE_FORMAT function.
DATE_FORMAT(`comments`,`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment`
Has 3.

(You have a comma between `comments` and `last_comment`) I don't know if thats a typing error :P

More info here: http://www.w3schools.com/sql/func_date_format.asp

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 7:00 am
by i3c
hello abcedea,

:oops: :oops: thats feels so
i have watch the video 10 times and didn't see it was a . or a ,
im feeling so ashamed at this point.

sorry and thanks ill test it :)

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 7:09 am
by Helx
i3c wrote:hello abcedea,

:oops: :oops: thats feels so
i have watch the video 10 times and didn't see it was a . or a ,
im feeling so ashamed at this point.

sorry and thanks ill test it :)
Play in HD :)

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 7:20 am
by i3c
i have it in HD :)
but i was so focused on all the things i didn't see i had a , instead of a .
i even see on the first line of data_time i had a .

and the next date_format i had a ,

so thats makes me a idiot i guess :(

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 7:44 am
by Helx
i3c wrote:so thats makes me a idiot i guess :(
Oh don't be ridiculous :) Its just a typo. We all do it.

Re: blog a Tutorial by jacek

Posted: Fri Sep 21, 2012 8:02 am
by i3c
YAY got it working.

it was hard :( but we made it.
thanks guys and jacek for this great video even it was hard to write :)