EDIT: I just realized I should have posted this in the MySQL section. If a mod can move it there I'd appreciate it. Thanks :)
Hi all
I have two tables. The first one has the details of each fruit, its code, markup percentage, it's cost price and the amount per bag. The second table is a "cart" where people select what fruit they want to buy. All that is stored in that table is the fruits code, how many units of that fruit they want and their session code.
What I need to do is calculate prices based on the information from Table Fruit with the items someone has selected in Table Cart.
What I'm doing at the moment is selecting all the information from Table Fruit and assigning it to variables. The problem is that the last row selected always overrides the variables. So I tried creating arrays to store each column of data in but my page doesn't display when I assign the arrays. Example below:
$name = array;
// select statement goes here
while($row = mysql_fetch_row($result))
{
$name += $row[0];
}
I then looked up JOINS and that doesn't help me because there are going to be multiple different session values in Table Cart.
Example: I need to take row 1 in Table Cart and get the price, markup and amount from Table Fruit in order to work out how much the person's order of apples is going to cost them. The same goes for the rest of their order.
So the person has seleceted 3 packets of 10 apples each with a 10% markup on the cost price which is 50.5.
(($price + ($price * $markup)) * $amount) * $units;
Total should be 1666.5 if the way I'm calculating it is correct.
Below you'll see examples of two tables that I have.
Table Fruit:
name | code | markup | price | amount
Apples | A10 | 10 | 50.5 | 10
Bananas | B10 | 5 | 50.5 | 10
Pineapples | P10 | 5 | 25.5 | 10
Melons | M1 | 5 | 100.5 | 1
Table Cart
session | units | code
abcdef | 3 | A10
abcdef | 1 | B10
abcdef | 5 | M1
Thanks in advance for any help ;)