SQL SUM function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

SQL SUM function

DAM-2

I'm developing web based application.
example table
create table item{
....
price decimal(12,2) notnull,
....
}

I want to show sum of price.How I can do it?

SQL query ( SELECT SUM(price) as price FROM.....)

but I want to that implement using cakephp.

Please help me This is for my university project.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

Edinei L. Cipriani
Hi,

$this->Model->find('all', array('fields' => array('Model.id'.'SUM(Model.price) AS price' ));

Regards


2009/9/30 DAM <[hidden email]>

I'm developing web based application.
example table
create table item{
....
price decimal(12,2) notnull,
....
}

I want to show sum of price.How I can do it?

SQL query ( SELECT SUM(price) as price FROM.....)

but I want to that implement using cakephp.

Please help me This is for my university project.





--
Edinei L. Cipriani
Desenvolvedor Colégio Trilingue Inovação
www.colegioinovacao.com.br
Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
Integrante do grupo Fool N Lost de algoritimos computacionais
Fone 49 84149086

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

brian-9

But read this post:

http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/

Cake will not put the data for the calculated field under the model
name in the data array. Put Teknoid's code in your AppModel and you'll
be good to go.

On Wed, Sep 30, 2009 at 3:20 PM, Edinei L. Cipriani <[hidden email]> wrote:

> Hi,
>
> $this->Model->find('all', array('fields' =>
> array('Model.id'.'SUM(Model.price) AS price' ));
>
> Regards
>
>
> 2009/9/30 DAM <[hidden email]>
>>
>> I'm developing web based application.
>> example table
>> create table item{
>> ....
>> price decimal(12,2) notnull,
>> ....
>> }
>>
>> I want to show sum of price.How I can do it?
>>
>> SQL query ( SELECT SUM(price) as price FROM.....)
>>
>> but I want to that implement using cakephp.
>>
>> Please help me This is for my university project.
>>
>>
>
>
>
> --
> Edinei L. Cipriani
> Desenvolvedor Colégio Trilingue Inovação
> www.colegioinovacao.com.br
> Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
> Integrante do grupo Fool N Lost de algoritimos computacionais
> Fone 49 84149086
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

DAM-2
In reply to this post by Edinei L. Cipriani



On Sep 30, 12:20 pm, "Edinei L. Cipriani" <[hidden email]> wrote:

> Hi,
>
> $this->Model->find('all', array('fields' =>
> array('Model.id'.'SUM(Model.price) AS price' ));
>
> Regards
>
> 2009/9/30 DAM <[hidden email]>
>
>
>
> Thankx for answer.
I tried that but not working.

controller

$payments = $this->Payment->find('all',array('fields'=>array
('Payment.id','SUM(Payment.amount) as price')));
$this->set(compact('purchaseorders','payments'));


view

        <?php foreach ($payments as $payment): ?>
        <?php echo $payment['Payment']['price']; ?>
        <?php endforeach;?>

result

Notice (8): Undefined index:  price [APP\views\payments\add.ctp, line
6]


why?
>
> --
> Edinei L. Cipriani
> Desenvolvedor Colégio Trilingue Inovaçãowww.colegioinovacao.com.br
> Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
> Integrante do grupo Fool N Lost de algoritimos computacionais
> Fone 49 84149086
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

Edinei L. Cipriani
Hi,

debug with print_r makes one and verifies what it returned

Em 01/10/2009, às 14:46, DAM escreveu:




On Sep 30, 12:20 pm, "Edinei L. Cipriani" <[hidden email]> wrote:
Hi,

$this->Model->find('all', array('fields' =>
array('Model.id'.'SUM(Model.price) AS price' ));

Regards

2009/9/30 DAM <[hidden email]>



Thankx for answer.
I tried that but not working.

controller

$payments = $this->Payment->find('all',array('fields'=>array
('Payment.id','SUM(Payment.amount) as price')));
$this->set(compact('purchaseorders','payments'));


view

<?php foreach ($payments as $payment): ?>
<?php echo $payment['Payment']['price']; ?>
<?php endforeach;?>

result

Notice (8): Undefined index:  price [APP\views\payments\add.ctp, line
6]


why?

--
Edinei L. Cipriani
Desenvolvedor Colégio Trilingue Inovaçãowww.colegioinovacao.com.br
Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
Integrante do grupo Fool N Lost de algoritimos computacionais
Fone 49 84149086




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

DAM-2

thanks for your help!!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

DAM-2
In reply to this post by brian-9

Thanks a lot
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

Edinei L. Cipriani
how did it return in print_r?

See u

2009/10/1 DAM <[hidden email]>

Thanks a lot




--
Edinei L. Cipriani
Desenvolvedor Colégio Trilingue Inovação
www.colegioinovacao.com.br
Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
Integrante do grupo Fool N Lost de algoritimos computacionais
Fone 49 84149086

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

DAM-2

Array
(
    [0] => Array
        (
            [Payment] => Array
                (
                    [id] => 0000000001
                )

            [0] => Array
                (
                    [price] => 596945.00
                )

        )

)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

Edinei L. Cipriani
congratulations!

2009/10/1 DAM <[hidden email]>

Array
(
   [0] => Array
       (
           [Payment] => Array
               (
                   [id] => 0000000001
               )

           [0] => Array
               (
                   [price] => 596945.00
               )

       )

)





--
Edinei L. Cipriani
Desenvolvedor Colégio Trilingue Inovação
www.colegioinovacao.com.br
Cursando Sistemas de Informação  - Unoesc Chapecó 1 Período
Integrante do grupo Fool N Lost de algoritimos computacionais
Fone 49 84149086

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: SQL SUM function

vishnu priya
This post has NOT been accepted by the mailing list yet.
I did the same way but  i am getting same error