On 7 ago, 11:15, albe <[email protected]> wrote:
> I have found a solution in this way:
>
> $post['Post']['haswarnings'] = count($this->Warning->query("SELECT *
> FROM `db`.`warnings` WHERE `post_id` ='".$post_id."'"));
>
> Thank you, anyhow!
>
For that you'd use ->find('count', array('conditions' =>
$conditionsAnArray));
why bother using cake if you aren't going to 'use' it.
> The "function view" that permits to shows the posts contains a foreach
> cycle, so I need to make the query each and every round of the cycle
> to control the amount of the warnings for that specific post
>
> foreach ($levels as $post_id) {
> ...
> $post['Post']['haswarnings'] = ($this->Warning->query("SELECT COUNT
> ( * ) FROM `db`.`warnings` WHERE `post_id` ='".$post_id."'"));
> ...
>
>}
why would you do that instead of either use a group by, or even
simpler counterCache? Either of which would mean 1 query and not n.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---