mysql - PHP - getting the first sum number only
There are 5 types of prices that have been summed-up in each div using MySQL query and works perfectly.
Then, I wish to get the sum of those 5 total values by giving them each a
$_SESSION variable before it sum them all up. It only gets the first price but still sums them up perfectly.
$extra_price is 25 then if i
$total can get 50)
Lets say if (e.g
$extra_price is 25 and
$decoprice is 10 then i sum
$total only show 25) the 10 has been ignore.
Any idea how to get the sum perfectly ?
Below is my code:
<?php $extra_price = $_SESSION['extra_price']; $decoprice = $_SESSION['decoprice']; $foodprice = $_SESSION['foodprice']; $drinksprice = $_SESSION['drinksprice']; $venueprice = $_SESSION['venueprice']; $total = $extra_price+$decoprice+$foodprice+$drinksprice+$venueprice; ?> <center><b>Total <?php echo $total ?></b></center>
U shouldnt use this syntax
Try to name you
SUM(decoprice)and use it to register the session.
You don't need all those extra variables, you can just write it like this:
Obviously, this is irrelevant, just an issue of style. In any case the
+operator will sum things perfectly for you. That's what it does. It sums things. Perfectly.
But the problem is, nobody knows what's in your $_SESSION. Do you? Why don't you try logging it somewhere or at least doing:
Then you will see that your session probably doesn't contain what you think it does.
Hey first of all you don't need session here. Simple declare total variable at top of your code and replace each session with total variable with plus. and remove extra variables.
Do with all session.
Here is your full code: