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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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