This is a tricky question to ask. A friend of mine seeks help, and I am not really into the project so it is difficult to describe the problem.
He has a shopping cart written in PHP, and in that shopping cart he wants all the product prices to be counted into a total price.
The problem is, all the prices are in a MySQL database. Displaying the prices (with decimals) is not a problem but, when these prices are counted and put in a variable, the decimals are not shown.
How can we solve this problem?
I will show you the code that he uses for displaying the prices in the shopping cart:
// Show cart
foreach($cart as $products) {
// Split
/*
$product[x] -->
x == 0 -> product id
x == 1 -> hoeveelheid
*/
$product = explode(",",$products);
// Get product info
$sql = "SELECT product_nummer, productnaam, verkoopprijs
FROM product
WHERE product_nummer = ".$product[0]; // Komt uit de sessie
$query = mysql_query($sql) or die (mysql_error()."<br>in file ".__FILE__." on line ".__LINE__);
$pro_cart = mysql_fetch_object($query);
$i++;
$price = $pro_cart->verkoopprijs; // variable price aanmaken zodat er opgeteld wordt
echo "<tr>\n";
echo " <td>"." • ".$pro_cart->productnaam."</td>\n"; // naam
echo " <td><input type=\"hidden\" name=\"productnummer_".$i."\" value=\"".$product[0]."\" />\n"; // wat onzichtbare vars voor het updaten
echo " <input type=\"text\" name=\"hoeveelheid_".$i."\" value=\"".$product[1]."\" size=\"2\" maxlength=\"2\" /></td>\n";
echo " <td class=\"rechtsuitlijnen\">"."€ ".$pro_cart->verkoopprijs."</td>"."\n";
$lineprice = $product[1] * $price; // regelprijs uitrekenen > hoeveelheid * prijs
echo " <td class=\"rechtsuitlijnen\">"."€ ".$lineprice."</td>\n";
echo " <td><a href=\"javascript:removeItem(".$i.")\">X</td>\n"; //Product verwijderen
echo "</tr>\n";
// Total
$total = $total + $lineprice; // Totaal updaten
}
?>