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:
any help please.
thanks
blog a Tutorial by jacek
Re: blog a Tutorial by jacek
After your query add,
[syntax=php]
echo mysql_error();
[/syntax]
It will give you a more detailed description of the error.
[syntax=php]
echo mysql_error();
[/syntax]
It will give you a more detailed description of the error.
Re: blog a Tutorial by jacek
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?
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
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
More info here: http://www.w3schools.com/sql/func_date_format.asp
[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
More info here: http://www.w3schools.com/sql/func_date_format.asp
Re: blog a Tutorial by jacek
hello abcedea,
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
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
i3c wrote:hello abcedea,
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
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
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
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
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
it was hard but we made it.
thanks guys and jacek for this great video even it was hard to write