What I have is a query that outputs sizes and weights of an object from fields in the table. All are user inputs. It then calculates the best way to package these and calculates a delivery cost. That could be a tricky bit, but it works perfectly. I finish up with a variable called $fincharge. I have done this with php passed back through AJAX to the page (for want of a better way of phrasing this).
Naturally, real-life also requires that I can deal with multiple items per delivery, so I effectively finish with several $fincharge(s) in a php do .. while formatted on the page.
I think that makes sense, but sometimes when you're close to a problem, it's hard to explain clearly.