Jump to content

Help: Posting Multiple Arrays And Calculating Their Values.


Recommended Posts

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";

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.

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.