Without seeing your sql code, it's hard to help, but I recommend you
learn the Model methods available to you, as it can often shorten the
amount of code needing to be written. Often I use a mixture between
arrays and strings for my conditions, etc, depending on how
complicated the query is.
$unreadCount = $this->MyModel->find('count', array('conditions' =>
'status < 1'));
which is the equivalent of:
$sql = "SELECT COUNT(*) as unread_count FROM my_models WHERE
my_models.status < 1";
$results = $this->MyModel->query($sql);
$unreadCount = $results[0][0]['unread_count'];
You can also go a step further and put the "find" logic into your
model, but just take one step at a time :)
Cheers,
Adam
Rimoe wrote:
> hi,everyone!
>
> I'm a newbie.
>
> I have saw In the bake view, If you want to use the resultset,
> only use the $form->input('mail'),
>
> but the find result ()
> In the controller
> $unreadcounts==$this->query($sql);
> $this->set(compact('unreadcounts'));
>
> in the view, I must to get the result use the
> $unreadcounts[0][0]['unread'];
> It's so long.
> what has the short method to get the result of 'unread'
>
> Thank U.
>
> rimoe
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---