JJohnsenDK Posted May 23, 2007 Share Posted May 23, 2007 Hey Im trying to figure out how i multiply this: <?php $cartQuery = mysql_query("SELECT items, color, product_product_id, payment_method FROM shop_cart WHERE temp_id = '".$_SESSION['cart_id']."'") or die(mysql_error()); $i = 1; while($cartRow = mysql_fetch_array($cartQuery)){ $price = get_product_price($cartRow['product_product_id']); $items = $cartRow['items']; $total = $price * $items; echo $total."<br />"; } ?> now the variable $total holds the numbers i want to multiply together. How do i do this? i tried $test = $total + $total; that didnt work. Hope you guys have someohter solution? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 23, 2007 Share Posted May 23, 2007 What do you mean by "now the variable $total holds the numbers i want to multiply together?" The asterisk should work ("$total = $price * $items"). What result are you actually getting? Quote Link to comment Share on other sites More sharing options...
radar Posted May 23, 2007 Share Posted May 23, 2007 By al logic of the code, it should work... The only thing I could think is that it is thinking the things that are in $price and $items are strings instead of number... so try putting this in... <?php if (!is_numeric($price) { echo "price is not numeric"; } elseif (!is_numeric($items) { echo "items is not numeric"; } else { $total = $price * $items; echo "".$total."<br>"; } ?> put that in and see what it does... that way it'll tell you if it isn't numeric or what.. Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 can also do it this way... $price*=$quantity; or the likes :-) Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted May 23, 2007 Author Share Posted May 23, 2007 Yes it works fine and gives me the result of items * price. But then i also want the result of all the items and prices that have been multiplied together. See: 3 items of Footballs. 1 item 100 - 3 items 300 5 items of Gloves. 1 item 200 - 5 items 1000 This would give me a total of 1300 I only figured out how i get 300 and 1000. So what im asking is how i get that total result? Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted May 23, 2007 Author Share Posted May 23, 2007 i think i got it wrong with multipling... i meant plus Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 just on your loop... have $grandtotal+=$total; Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted May 23, 2007 Author Share Posted May 23, 2007 ofcause you have the answer taith Thanks mate Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 i try Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.