Calcualting a figure

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Calcualting a figure

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, they need to be in variables (or inline) to multiply.
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post 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
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Yes. That certainly seems to be the right direction.
Post Reply