On Jul 6, 8:40 pm, mussond <[EMAIL PROTECTED]> wrote:
> Hey all, I have this SQL query that I want to use. The idea is that
> the user will select the id from a HTML select box and then click a
> submit button.
>
> SELECT count(*) as c
> FROM data_points p join des_walks w
> WHERE p.des_walk_id = w.id AND w.com_user_id = 1
>
> I've got the following code in my controller that I put together from
> searching on the forurm:
>
> function index()
> {
> $this->DataPoint->recursive = 0;
> $this->set('datapoints', $this->DataPoint->findAll());
> $comUser = $this->ComUser->generateList('id');
> $this->set('comUser', $comUser);
>
> $sql = 'SELECT count(*) as c '
> . ' FROM data_points p join des_walks w '
> . ' WHERE p.des_walk_id = w.id AND w.com_user_id = ' .$comUser;
> $result = $this->DataPoint->query($sql);
> $this->set('data', $this->DataPoint->query($sql));
>
> }
what's wrong with either:
$anInt = $this->DataPoint->DesWalk-
>findCount(array(¨DesWalk.com_user_id' => $comUser))
OR even
$anInt = $this->DataPoint->DesWalk->findCount(array('User.id´ =>
$comUser));
?
I am assuming in the above you have a DesWalk model which belongs to
User & DataPoint, if you needed a DataPoint constraint you can just
stick it in the conditions (as done for User in the second example).
I don't get why lately there are so many questions on how to use
query, when the same can be achieved (much easier) using the methods
of the framework.
In this case is the method findCount not prominent enough in the docs
(http://manual.cakephp.org/chapter/models) or something?
AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---