what kind of data structure are you using?...can you show some code? Are you assembling the cart items in an array?...
all you would need to do to get the price out of the db is follow the same structure as before--
instead of just doing the total, you can run queries against the database to get the price per item (not really very efficient, but it works), and then total them....or you can have the total returned by the query...use the sum function