Page 1 of 1

Calcualting a figure

Posted: Thu Feb 24, 2005 4:06 pm
by shab620
Hye

I'm building an online ordering system for a project at Uni, What I'm attempting to do is calcualte a figure based on the quantity and price. At the moment the user selects from a series of radio buttons which then uses the value to lookup in another table the item description and then inserts that details along with other user entry such as the quantity into an order table. The item table does contain a value for price.

What my question is how would i go by calculating the two togeother and then inserting that value into the order table along with the other details which are currently being passed.
Would a function need to be implemented or something else?

Hope someone can help :D :D

Posted: Thu Feb 24, 2005 4:23 pm
by feyd
select the price from the item table, multiple the price by quanitity passed, store the results in the order table.

I'd suggest storing an item id, order id (since multiple items can be in an order), and quantity requested as a row in the order table. Perform a quick check against available inventory to make sure the quantity is valid. When the user reaches a checkout page, you can total the items in their order together by simple multiplying the quantity and item price (found through a join query). A seperate table links the user to the order.


http://www.oreilly.com/catalog/javadtab ... r/ch02.pdf

Posted: Thu Feb 24, 2005 4:33 pm
by shab620
hye

I was wondering how i would multiply the two togeother. I'm quite new to PHP so have limited experince.
If you could give me a starting hand that would be great

Would i have to place the values into a variable and then times the two togorther?

Shab

Posted: Thu Feb 24, 2005 4:35 pm
by feyd
yes, they need to be in variables (or inline) to multiply.

Posted: Thu Feb 24, 2005 4:44 pm
by shab620
the way in which i think i will do this task is by querying the table for the price based on the user input. I will obtain the quantity from the user input which will be posted from the input form. the basic code is as follows:

$totalprice = $quantity * $attribute

the $attribute will be from the query reults fro the price and the $quantity will be taken from the user input and then the post function.

$totalprice will then be inserted into the orders table.

Am i on the right lines???

Shab
p.s thanks for the help so far, :D :D

Posted: Thu Feb 24, 2005 10:51 pm
by smpdawg
Yes. That certainly seems to be the right direction.