blog a Tutorial by jacek

Ask about a PHP problem here.
Post Reply
User avatar
i3c
Posts: 14
Joined: Thu Sep 20, 2012 9:56 am
Contact:

blog a Tutorial by jacek

Post by i3c »

hello,

seems i got a error and i don't know where or what it can be.

[syntax=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){

$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;

}
[/syntax]

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

the error contains:
Image

any help please.
thanks
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: blog a Tutorial by jacek

Post by EcazS »

After your query add,
[syntax=php]
echo mysql_error();
[/syntax]
It will give you a more detailed description of the error.
User avatar
i3c
Posts: 14
Joined: Thu Sep 20, 2012 9:56 am
Contact:

Re: blog a Tutorial by jacek

Post 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?
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: blog a Tutorial by jacek

Post by Helx »

You can only have 2 parameters in MySQL's DATE_FORMAT function.

[syntax=sql]DATE_FORMAT(`comments`,`last_comment`, '%d/%m/%Y %H:%i:%s') AS `last_comment`[/syntax]
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
User avatar
i3c
Posts: 14
Joined: Thu Sep 20, 2012 9:56 am
Contact:

Re: blog a Tutorial by jacek

Post 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 :)
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: blog a Tutorial by jacek

Post 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 :)
User avatar
i3c
Posts: 14
Joined: Thu Sep 20, 2012 9:56 am
Contact:

Re: blog a Tutorial by jacek

Post 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 :(
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: blog a Tutorial by jacek

Post 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.
User avatar
i3c
Posts: 14
Joined: Thu Sep 20, 2012 9:56 am
Contact:

Re: blog a Tutorial by jacek

Post 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 :)
Post Reply