I have the following function to display posts on my site. It works fine on my localhost but when I uploaded the files to the server I got the following warning:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
I can’t see what I am doing wrong because it works just fine on localhost. Any ideas?
function get_posts() {
$query = mysql_query("SELECT
`post_title`,
`post_name`,
`post_body`,
`post_date`,
`author_title`,
`author_name`
FROM `posts`
WHERE `post_type` = 'post'
LEFT JOIN `authors` ON `author_id` = `post_author`
ORDER BY `post_id` DESC LIMIT 0,8");
while ($row = mysql_fetch_assoc($query)) { $posts[] = $row;}
return $posts;
}
It is solved now, thanks for your help Chris and Rudy.
Following was the error I got:
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 'LEFT JOIN authors ON author_id = post_author ORDER BY post_id …
Thanks for the tip, I will definitely test my queries when I get such errors the next time. I now have the following and it works perfectly.
$query = mysql_query("SELECT
`post_title`,
`post_name`,
`post_body`,
`post_date`,
`author_title`,
`author_name`
FROM `posts`
LEFT JOIN `authors` ON `author_id` = `post_author`
WHERE `post_type` = 'post'
ORDER BY `post_id` DESC LIMIT 0,8");
I guess that my first query worked on the localhost and not on the server because they have different MySQL versions.