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? Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/ 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? Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259912 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.. Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259917 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 :-) Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259919 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? Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259920 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 Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259921 Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 just on your loop... have $grandtotal+=$total; Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259926 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 Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259931 Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 i try Link to comment https://forums.phpfreaks.com/topic/52655-solved-multipling-in-php/#findComment-259935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.