Jump to content

[SOLVED] Multipling in PHP


JJohnsenDK

Recommended Posts

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

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..

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.