Author Topic

Nathan Kelly

Friday 23 February 2007 9:40:39 pm

Comment47826

Hi Kracker,

I can appreciate what you are suggesting and under normal circumstances I would post up a package but this problem I faced was only a tiny part of a very large extension, on its own it really has no relevance as packaged solution, and as a lesson there really is nothing else in the extension that isn't in most of the extensions already available.

Also this solution was for one very specific query to the database, for the best part the rest of the extension interacts with the ezPersistantObject without issue, but because my custom query was quite a complex one I found myself stuck for a solution, and due to my lack of understanding of how extensions interact with Exponential I was not aware that I could simply create a query that could be inserted directly into the template variable as Bruce pointed out.

By the time I finally finished the query the complexity had grown from a simple query to the following:

$result = "SELECT DISTINCT tableOne.*, count(tableTwo.myObjectID) 
FROM tableOne, tableTwo 
WHERE tableOne.myObjectID 
IN (tableTwo.myObjectID) 
AND tableTwo.myCondition = 2 
GROUP BY tableOne.myObjectID 
ORDER BY myObjectName ASC";
$db =& eZDB::instance();
$template_var =& $db->arrayQuery($result);

The final product works as I wanted it too, it collects and counts information depending on whether it is in use or not and returns only the objects that are in use, while returning a total count of myObjectID groups and their children.

One thing that stumped me however was how to use the count key which is returned as count(tableTwo.myObjectID). After some serious guess work I got the count value with the following:

{foreach $template_var as $var}
{$var['count(tableTwo.myObjectID)']}
{/foreach}

Seems odd but works fine...

The real issue here was my lack of understanding of when I need to use the ezPersistantObject and when I can do without it. The only thing I can suggest that might help others avoid the problem I faced is try to familiarize yourself with the core functionality, that's what i am going to start doing from now on, it can be frustrating when everything works and suddenly you hit a wall where your own understanding lets you down.

In future if I am doing something smaller and i think it could help other I'll definitely post up a solution.

Cheers.

Pardon me while I burst into flames...