2009年9月2日星期三

SV: [fw-db] Zend_Db_Table along with a COUNT() expression on a child table.

Hi Andreas,

Thank you for your suggestion but it did not seem to work. It looks like the count was working ok but all the other values from the various colums I was also retreiving returned NULL.
You might be right about the Zend_Db_Expr and I've had a look at it on the Reference Guide but it leaves me a bit confused. As far as I can see from the examples, Zend_Db_Expr is being used through the from method.
I'm already working inside a Zend_Db_Table instance and so I'm a puzzled about how to make use of the examples from the Reference Guide. I've done done some various trial and error with the way it's being done in the examples but don't seem to have any luck.

I'm wondering if you, or anyone else reading this, could find the time to provide a more concrete example on how it should be done. Any help will be much appreciated.

Kind regards
Christian Rasmussen
________________________________________
Fra: Andreas Kraftl [andreas.kraftl@kraftl.at]
Sendt: 1. september 2009 15:55
Til: fw-db@lists.zend.com
Emne: Re: [fw-db] Zend_Db_Table along with a COUNT() expression on a child table.

Am Dienstag, den 01.09.2009, 15:02 +0200 schrieb Christian Aarø
Rasmussen:

> So far, I seem to have made the first part work. It's the COUNT() I
> can't really get to work and I'm hoping that some of your guys and
> girls may be of some assistance.
>
> So far, the code I'm trying out with, looks like this:
>
> $select= $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
> $select ->setIntegrityCheck(false)
>
> ->where('category_id = ?', $categoryId)
>
> ->join('users_information', 'users_information.id =
> todo_entries.id', array('user_id'=> 'id', 'name', 'username'))
>
> ->join('todo_comments', 'todo_comments.id =
> todo_entries.id', array('num_comments'=> 'COUNT(*)'));

Try (COUNT(*)) instead of COUNT(*). Means, include the parenthesis.
If this doesn't work, try it with a Zend_Db_Expr.
http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.columns-expr

Greetings
Andreas
--
Kraftl EDV - Dienstleistungen
Linux, Linuxschulungen, Webprogrammierung
Autofabrikstraße 16/6
1230 Wien

没有评论: