Joomap error at line 88 foreach()
I encountered a rather annoying error message in this CMS when I wanted to add a Sitemap component called joomap to Mambo (to improve Google indexing ).
XML Parsing Error: junk after document element
Location: http://www.orbit.me.uk /index.php? option=com_joomap&view=google
Line Number 2, Column 1:<b>Warning</b>: Invalid argument supplied for foreach() in <b>[snip] /administrator /components /com_joomap /plugins /content.plugin.php</b> on line <b>88</b><br />
This was a problem because it was stopping Google indexing the sitemap. So I decided to dust off my PHP and tackle the problem head on...
The problem was that there was no checking on the results of the SQL query before trying to break out an array of objects from the returned query. Well I did a var_dump on the result and it showed me:
NULL
So I decided the simple thing to do was to detect if there was a null before going into the foreach():
if(!is_null($items)) {
foreach($items as $item) {
etc...
}
}
and this has now solved the problem, for now. Although who knows what else is lurking in there!