Re: variable number of items in one table

2007-02-28 Thread mike

Thanks very much fo the reply.

I currently have the simple code below printing out of the values in
Orderlines.

foreach ($item as $index=$row) {

$price = $row['price'];
$qty = $row['qty'];

$total = $price*$qty;

echo $price;
echo $qty;
echo $total;

}

What I'd like to do next is add all $total in as many rows it prints.
Simple enough but not sure how.
I think I need to add a unique variable to $total on each loop then
add then all up when it breaks out of the loop ()
Does anyone have an example I could look at?

Thanks very much for the help so far!

Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-28 Thread mike

Found this answer and seems to work.

$sum = 0;

foreach($result as $row)
{
$sum += $row['price'];

}  Thanks Mariano


On Feb 28, 1:39 pm, mike [EMAIL PROTECTED] wrote:
 Thanks very much fo the reply.

 I currently have the simple code below printing out of the values in
 Orderlines.

 foreach ($item as $index=$row) {

 $price = $row['price'];
 $qty = $row['qty'];

 $total = $price*$qty;

 echo $price;
 echo $qty;
 echo $total;

 }

 What I'd like to do next is add all $total in as many rows it prints.
 Simple enough but not sure how.
 I think I need to add a unique variable to $total on each loop then
 add then all up when it breaks out of the loop ()
 Does anyone have an example I could look at?

 Thanks very much for the help so far!

 Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-26 Thread mike

I have setup table relations so that Order brings in Orderlines, but
this leads me to another problem. I somehow need to total the order
but this isn't as easy as I first thought. I'm wondering if anyone can
give any help on how to do this, probably a for loop i would think?

Thanks very much any help greatly appreciated!!

[0] = Array
(
[id] = 1
[ord_id] = 110
[price] = 12.00
)

[1] = Array
(
[id] = 2
[ord_id] = 110
[price] = 3.00
)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-26 Thread mike

I have searched this board high and low and cannot find a solution to
this problem

On Feb 26, 12:24 pm, mike [EMAIL PROTECTED] wrote:
 I have setup table relations so that Order brings in Orderlines, but
 this leads me to another problem. I somehow need to total the order
 but this isn't as easy as I first thought. I'm wondering if anyone can
 give any help on how to do this, probably a for loop i would think?

 Thanks very much any help greatly appreciated!!

 [0] = Array
 (
 [id] = 1
 [ord_id] = 110
 [price] = 12.00
 )

 [1] = Array
 (
 [id] = 2
 [ord_id] = 110
 [price] = 3.00
 )


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-26 Thread djiize

either you foreach the $data['Order']['Orderline'] and calculate the
sum of (price * quantity)
or either you add a sum field in your orders table thats is modified
when you add/edit/delete an orderline (maybe by an afterSave callback)

On 26 fév, 18:54, mike [EMAIL PROTECTED] wrote:
 I have searched this board high and low and cannot find a solution to
 this problem

 On Feb 26, 12:24 pm, mike [EMAIL PROTECTED] wrote:

  I have setup table relations so that Order brings in Orderlines, but
  this leads me to another problem. I somehow need to total the order
  but this isn't as easy as I first thought. I'm wondering if anyone can
  give any help on how to do this, probably a for loop i would think?

  Thanks very much any help greatly appreciated!!

  [0] = Array
  (
  [id] = 1
  [ord_id] = 110
  [price] = 12.00
  )

  [1] = Array
  (
  [id] = 2
  [ord_id] = 110
  [price] = 3.00
  )


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-25 Thread mike

Hi, Thanks for the advise.

In that case I'd have to have a form that wrote to both order and
Orderlines tables??

On Feb 24, 8:28 pm, djiize [EMAIL PROTECTED] wrote:
 Hi

 you need another table, call it orderlines for instance, with these
 fields:
 order_id
 item_id
 quantity
 ... and maybe some more

 and a belongsTo Order association
 When you retrieve an Order, you'll get its Orderlines too

 On 24 fév, 16:18, mike [EMAIL PROTECTED] wrote:

  Hi all,

  I have a small problem and wonder if I could get some advice on the
  best way to overcome it.

  What I want is an orders table where I can input data such as items,
  order reference, notes, delivery date etc. The table will be linked to
  a customer table. What I'm stuck on however if the best way to record
  the various order items (products) that go with the order. The amount
  of items will of course vary from order to order, so I'm wondering if
  there is a way to record a variable amount of data separately but
  within one static orders table. Or, maybe there is a need for another
  table linked into orders?

  Your advice and expertise is welcome and always greatly appreciated.

  Thanks,

  Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: variable number of items in one table

2007-02-24 Thread djiize

Hi

you need another table, call it orderlines for instance, with these
fields:
order_id
item_id
quantity
... and maybe some more

and a belongsTo Order association
When you retrieve an Order, you'll get its Orderlines too

On 24 fév, 16:18, mike [EMAIL PROTECTED] wrote:
 Hi all,

 I have a small problem and wonder if I could get some advice on the
 best way to overcome it.

 What I want is an orders table where I can input data such as items,
 order reference, notes, delivery date etc. The table will be linked to
 a customer table. What I'm stuck on however if the best way to record
 the various order items (products) that go with the order. The amount
 of items will of course vary from order to order, so I'm wondering if
 there is a way to record a variable amount of data separately but
 within one static orders table. Or, maybe there is a need for another
 table linked into orders?

 Your advice and expertise is welcome and always greatly appreciated.

 Thanks,

 Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---