ZenphotoCMS Forum
printMostPopularItems() incorrect MySQL syntax - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: Plugins (https://forum.zenphoto.org/forum-6.html)
+--- Thread: printMostPopularItems() incorrect MySQL syntax (/thread-7293.html)



printMostPopularItems() incorrect MySQL syntax - rjscotland - 04-07-2010

Hi,

I'm trying to make use of the printMostPopularItems() function in Zenpage. I'm having no luck as it just generates the following error:

MySQL Query ( SELECT id, title, titlelink, hitcounter, total_votes, rating FROMzp_zenpage_newsORDER BY DESC LIMIT 10 ) failed. MySQL returned the error 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 'DESC LIMIT 10' at line 1

This occurs on a FreeBSD box (Apache) running MySQL 5.0.51a and also a Windows box (Apache) running MySQL 5.1.30.

Unfortunately as I'm no MySQL guru I'm not sure where to start looking to debug it. Perhaps it'll be blindingly obvious to someone.

Cheers!




printMostPopularItems() incorrect MySQL syntax - kagutsuchi - 04-07-2010

What version of Zenphoto are you running?




printMostPopularItems() incorrect MySQL syntax - rjscotland - 04-07-2010

I'm running 1.3 (5479).




printMostPopularItems() incorrect MySQL syntax - sbillard - 05-07-2010

Could you post the actual code where you call printMostPopularItems()? Most likely this is caused by a parameter error.




printMostPopularItems() incorrect MySQL syntax - acrylian - 05-07-2010

I can confirm that a bug sneaked into that function. It will be corrected in the svn soon.




printMostPopularItems() incorrect MySQL syntax - rjscotland - 05-07-2010

Ah that's good to hear . Thanks a lot for your help!

Is it a quick fix? As in, can I edit the function myself to get it working in my current installation?

Cheers




printMostPopularItems() incorrect MySQL syntax - acrylian - 05-07-2010

Well, look at the function at the switch at the beginning. It checks $option but should actually check $mode.




printMostPopularItems() incorrect MySQL syntax - rjscotland - 05-07-2010

I've tweaked it...

`
function getZenpageStatistic($number=10, $option="all",$mode="popular") {
global $_zp_current_zenpage_news, $_zp_current_zenpage_pages;
$number = sanitize_numeric($number);
switch($mode) {
case "popular":
$sortorder = "hitcounter"; break;

...
`
...and it now works

Thanks a lot for that, well spotted!

On a side note, it would be nice if the printZenageStatistic() that the printMostPopularItems() uses didn't add $item['type'], or at least gave the option to toggle, but that's something for another day I think. Given that I'm editing the functions page anyway I'll just delete it from there but in the future I'll put the php to use with getZenpageStatistic() directly in the theme.




printMostPopularItems() incorrect MySQL syntax - acrylian - 05-07-2010

Actually there is the get variant for such customisations. But we could take that out, too.