noahyamen Posted December 1, 2012 Share Posted December 1, 2012 This one is a doozy for me. My brain is fried after spending a couple days trying to figure this out. None of my formulas have seemed to work out enough. So I'm waiving my white flag and asking for some help. Below is a simplified version of my code. The purpose of this page is an estimate calculator. It is for a window cleaning service, and they have pricing for doing the insides of windows and the outsides. Each style of window has different pricing for each inside and outside. What is supposed to happen in the form is this: If they want an estimate for say basic window cleaning for both inside and outside, they will check the chechboxes for both inside and outside. Then enter a number for the amount of windows to clean. The formula for this would look something like this: Amount = Inside Price x Outside Price (if inside price and outside price checkboxes are ticked). And for each entry, it needs to add up the total. But none of the foreach or while loops i try to create seem to do the trick. Basic Form Setup: $query = "SELECT * FROM estimates WHERE 1 ORDER BY id ASC"; $result = mysql_query($query); while ($estimates = mysql_fetch_object($result)) { $style = $estimates->style; $insidePrice = $estimates->price; $outsidePrice = $estimates->out; echo $style.' <input type="checkbox" name="insidePrice[]" value ="'.$insidePrice,'" /> $'.$insidePrice.' <input type="checkbox" name="outsidePrice[]" value ="'.$outsidePrice,'" /> $'.$outsidePrice.' <input type="text" name="amount[]" />'; } And an idea of how i want this to work: foreach ($_POST['amount'] as $key => $a){ if ($a != "" or $a !="0"){ //Now to llustrate what Im trying to do, I know this is wrong though foreach ($_POST['insideAmount'] as $i){ $i = $i*$a; } foreach ($_POST['outsideAmount'] as $o){ $o = $o*$a; } $a = $i+$o; } //Trying to add each row as they build to make the estimate total $prev = $a[$key-1]; $a = $a+$prev; $total = $a; } echo "$total"; Quote Link to comment Share on other sites More sharing options...
noahyamen Posted December 1, 2012 Author Share Posted December 1, 2012 Also, when I was able to at least return data from each checkbox, it wasn't returning the value. It would only display "on". Couldn't figure out why. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2012 Share Posted December 1, 2012 $total = 0; foreach ($_POST['amount'] as $key => $a) { $i = $_POST['insideAmount'][$key]; $o = $_POST['outsideAmount'][$key]; $total += $a * ($i + $o); } echo $total; 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.