Not sure if this has already been posted, I tired a few hours ago but
I've had net problems all day so.

Thanks for the help, I've changed my code to use findCount but I'm
having trouble with getting the correct index from $comUser.

The first index in the list (HTML select) is and id of 1, which should
return a count of 25.  but the code below returns 40.  Which is the
number of rows in the table:

        $anInt = $this->DataPoint->findCount(array('DataPoint.des_walk_id' =>
$comUser));
        $this->set('data', $anInt);

So I changed it so it has an index - $comUser[1] and I get the correct
count.  The same if I change the number to to 2.

My trouble is how do I change $comUser[1]  to $comUser[value that is
selected in $comUser].

I've tried $comUser[$comUser] and some variants of that idea.

Anyone now how it can be done?

On Jul 10, 3:45 am, AD7six <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to