aebstract Posted January 22, 2008 Share Posted January 22, 2008 $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 More sharing options...
wildteen88 Posted January 22, 2008 Share Posted January 22, 2008 Remove the quotes on this line: $total = "$total + ($price * $quan)"; Link to comment https://forums.phpfreaks.com/topic/87236-solved-equation-doesnt-display-answer/#findComment-446251 Share on other sites More sharing options...
aebstract Posted January 22, 2008 Author Share Posted January 22, 2008 wow... I swear I tried that like 3 times, but it worked. Link to comment https://forums.phpfreaks.com/topic/87236-solved-equation-doesnt-display-answer/#findComment-446257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.