Canman2005 Posted November 26, 2007 Share Posted November 26, 2007 hi all i have the following query <?php $sql1 = "SELECT * FROM bes_optionals ORDER BY title ASC"; $show1 = @mysql_query($sql1,$connection) or die(mysql_error()); while ($row1 = mysql_fetch_array($show1)) { if($row1['type'] == 1) { if($_GET[$row1['id']] == 1) { print $row1['cost']; } } elseif($row1['type'] == 2) { if($_GET[$row1['id']] == 1) { print $row1['cost']; } elseif($_GET[$row1['id']] == 2) { print $row1['cost']*2; } elseif($_GET[$row1['id']] == 3) { print $row1['cost']*3; } elseif($_GET[$row1['id']] == 4) { print $row1['cost']*4; } } } ?> it basically outputs a series of numbers that were selected from a form on the previous page. the output looks something like 7.0010 which is 7.00 and 10 is it possible to add up all numbers outputted so it gives a result of 17? any help would be ace thanks in advance ed Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 Give this a try <?php $sql1 = "SELECT * FROM bes_optionals ORDER BY title ASC"; $show1 = @mysql_query($sql1,$connection) or die(mysql_error()); $cost = 0; while ($row1 = mysql_fetch_array($show1)) { if ($row1['type'] == 1) { if ($_GET[$row1['id']] == 1) { $cost += $row1['cost']; } } else if ($row1['type'] == 2) { if ($_GET[$row1['id']] == 1) { $cost += $row1['cost']; } else if ($_GET[$row1['id']] == 2) { $cost += $row1['cost']*2; } else if ($_GET[$row1['id']] == 3) { $cost += $row1['cost']*3; } else if ($_GET[$row1['id']] == 4) { $cost += $row1['cost']*4; } } } echo "Total: " . $cost; ?> Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted November 26, 2007 Author Share Posted November 26, 2007 nice one thanks very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.