The matter is a view of a forum site that has to show an alert for
every post that has been warned by one or more user.
I have a "posts" table and a "warnings" table. The warning table
contains (*user_id,*post_id,reason)
When the view shows all the posts of a discussion I want them to have
an alert beside if they have been warned.
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."'"));
...
}

How can I do otherwise?

On 7 Ago, 07:01, John Andersen <[email protected]> wrote:
> Hi,
>
> What are you trying to count? Can't you use the count method in the
> model class?
>
> Please show some more information on the SQL statement!
>
> Enjoy,
>    John
>
> On Aug 7, 2:32 am, albe <[email protected]> wrote:
>
> > Hi everybody!
> > maybe my problem is banal but I really don't know how to solve it:
>
> > I wrote a query in a controller and put the result in a variable, in
> > this way:
>
> > $variable['Model']['field'] = ($this->Model2->query("SELECT COUNT
> > ( * )...");
>
> > The result of the query is something like this:
>
> > Array
> > (
> >     [0] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [COUNT( * )] => 1
> >                 )
>
> >         )
>
> > )
>
> > Since I have to use this result in the relative view in order to make
> > comparisons (if $variable.Model.field > 0) I need the PURE NUMBER,
> > cleaned by the structure posted above.
> > Otherwise the comparisons wouldn't be correct!
> > Thank you in advance...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to