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