MySQL Forums
Forum List  »  PHP

Re: Arithmetic error
Posted by: Barry Galbraith
Date: November 03, 2012 04:15PM

>$price=$price*$each_item['item_id'];

Surely you mean to multiply the price by the quantity, not the id!

Does this work?

<?php
$i = "1";
$each_item['item_id'] = "001";
$each_item['quantity'] = 5;
$product_name = "Thing-a-ma-jig";
$price = 1.50;

$price=$price*$each_item['quantity'];


$cartOutput ="<h2>Cart Item $i</h2>";
$cartOutput.="Item ID: " . $each_item['item_id']."<br/>";
$cartOutput.="Item Quantity: " . $each_item['quantity']."<br/>";
$cartOutput.="Item Name: " . $product_name."<br/>";
$cartOutput.="Item Price: " . $price."<br/>";

echo $cartOutput;
?>

And like LA says, this a php related to mysql forum, so your post should have some relevance to mysql.

Good luck,
Barry.



Edited 2 time(s). Last edit at 11/03/2012 06:01PM by Barry Galbraith.

Options: ReplyQuote


Subject
Written By
Posted
November 02, 2012 03:00PM
November 03, 2012 03:07AM
Re: Arithmetic error
November 03, 2012 04:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.