Jump to content

[SOLVED] equation doesnt display answer


aebstract

Recommended Posts

$result2 = mysql_query("SELECT * FROM parts ORDER BY id ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$total = "$total + ($price * $quan)";

}



$row_count++;
}
$parts .= "<tr cellspacing=6><td align=center></td><td></td><td></td><td>$total</td><td></td></tr>";

$parts .= "</table><p align=right>check out</p></form>";

 

The equation in there should be taking the qty and multiplying it by the price for each row that has a qty > 0. Then add that amount to the amount of the next row that does the same thing.. etc etc all the way to the end which will result in a final price. Right now it displays like this:

+ (5.99 * 15) + (0 * 16) + (0 * 16) + (0 * 16) + (0 * 9) + (0 * 4) + (0 * 556)

instead of displaying the answer, any reasons for this? or better ways of approaching this even?

Link to comment
https://forums.phpfreaks.com/topic/87236-solved-equation-doesnt-display-answer/
Share on other sites

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.