I am working on script and I am having the addition problems with PHP. Here is a sample piece of code that I am having a problem with.<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$OverallTotal = 0;<br />for ($i=0; $i<count($arr_Multiplier); $i++) {<br />Â Â Â Â $arr_EstimateTotal[$i]['ItemType'] = $arr_Multiplier[$i]['ItemType'];<br />Â Â Â Â $arr_EstimateTotal[$i]['Multiplier'] = 1 + $arr_Multiplier[$i]['Multiplier'];<br />Â Â Â Â for ($j=0; $j<count($arr_Estimate); $j++) {<br />Â Â Â Â Â Â Â Â if ($arr_Multiplier[$i]['ItemTypeID'] == $arr_Estimate[$j]['ItemTypeID']) {<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['ItemTotal'] = $arr_EstimateTotal[$i]['ItemTotal'] + $arr_Estimate[$j]['Total'];<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['MultTotal'] = ceil($arr_EstimateTotal[$i]['ItemTotal'] * $arr_EstimateTotal[$i]['Multiplier']);<br />Â Â Â Â Â Â Â Â Â Â Â Â $OverallTotal = $OverallTotal + $arr_EstimateTotal[$i]['MultTotal'];<br />Â Â Â Â Â Â Â Â }<br />Â Â Â Â }<br />}<br />for ($i=0; $i<count($arr_LaborMultiplier); $i++) {<br />Â Â Â Â $arr_LaborTotal[$i]['LaborType'] = $arr_LaborMultiplier[$i]['LaborType'];<br />Â Â Â Â $arr_LaborTotal[$i]['LaborTotal'] = ceil($int_LaborTotal * $arr_LaborMultiplier[$i]['LaborMultiplier']);<br />Â Â Â Â $OverallTotal = $OverallTotal + $arr_LaborTotal[$i]['LaborTotal'];<br />}<br /><br />// Building Table<br />echo '<table class="estimate">'."\n";<br />for ($i=0; $i<count($arr_EstimateTotal); $i++) {<br />Â Â Â Â echo 'Â Â <tr>'."\n";<br />Â Â Â Â echo 'Â Â Â Â <td align="right" colspan="8">';<br />Â Â Â Â echo str_replace($cfg['lang']['tag_total'],$arr_EstimateTotal[$i]['ItemType'],money_format($cfg['lang']['est_Material'], $arr_EstimateTotal[$i]['ItemTotal']));<br />Â Â Â Â echo ':</td>'."\n";<br />Â Â Â Â echo estimate_box('ETotal'.'_'.$arr_EstimateTotal[$i]['ItemTypeID'], $arr_EstimateTotal[$i]['MultTotal'], 50, 'Text', 7, 'right', 0, 0);<br />Â Â Â Â echo 'Â Â </tr>'."\n";<br />}<br />for ($i=0; $i<count($arr_LaborMultiplier); $i++) {<br />Â Â Â Â echo 'Â Â <tr>'."\n";<br />Â Â Â Â echo 'Â Â Â Â <td align="right" colspan="8">Total '.$arr_LaborTotal[$i]['LaborType'].':</td>'."\n";<br />Â Â Â Â echo estimate_box('LTotal'.'_'.$arr_LaborTotal[$i]['LaborTypeID'], $arr_LaborTotal[$i]['LaborTotal'], 50, 'Text', 7, 'right', 0, 0);<br />Â Â Â Â echo 'Â Â </tr>'."\n";<br />}<br />echo 'Â Â <tr>'."\n";<br />echo 'Â Â Â Â <td align="right" colspan="8">Total:</td>'."\n";<br />echo estimate_box('OTotal'.'_'.'T', $OverallTotal, 50, 'Text', 7, 'right', 0, 0);<br />echo 'Â Â </tr>'."\n";<br />echo '</form>'."\n";<br />?><!--c2--></div><!--ec2--><br />I am pulling data into the arrays "$arr_Multiplier", "$arr_Estimate" & "$arr_LaborMultiplier" and variable "$int_LaborTotal" from a MySQL database. The data is all correct. The problem is the value for "$OverallTotal" is incorrect. PHP is saying 4193, but when I add the values I get 4075 (791+269+810+585+1620=4075). See this <a href="http://www.jhollin1138.com/estimate.html" target="_blank">link</a> to the stripped down source code of the output (I have a screen-shot of the output but I couldn't get it to attach it). Some items don't have the problem, while others do.<br /><br />Does anyone have any ideas?<!--content-->
<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/oops.gif" style="vertical-align:middle" emoid="" border="0" alt="oops.gif" />I found my problem. Replacing the similar section of code in my first post with the code below, fixes the it.<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->for ($i=0; $i<count($arr_Multiplier); $i++) {<br />Â Â Â Â $arr_EstimateTotal[$i]['ItemType'] = $arr_Multiplier[$i]['ItemType'];<br />Â Â Â Â $arr_EstimateTotal[$i]['Multiplier'] = 1 + $arr_Multiplier[$i]['Multiplier'];<br />Â Â Â Â for ($j=0; $j<count($arr_Estimate); $j++) {<br />Â Â Â Â Â Â Â Â if ($arr_Multiplier[$i]['ItemTypeID'] == $arr_Estimate[$j]['ItemTypeID']) {<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['ItemTotal'] = $arr_EstimateTotal[$i]['ItemTotal'] + $arr_Estimate[$j]['Total'];<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['MultTotal'] = ceil($arr_EstimateTotal[$i]['ItemTotal'] * $arr_EstimateTotal[$i]['Multiplier']);<br />Â Â Â Â Â Â Â Â }<br />Â Â Â Â }<br />Â Â Â Â $OverallTotal = $OverallTotal + $arr_EstimateTotal[$i]['MultTotal'];<br />}<!--c2--></div><!--ec2--><!--content-->
Glad you sorted it out. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/oops.gif" style="vertical-align:middle" emoid="" border="0" alt="oops.gif" />I found my problem. Replacing the similar section of code in my first post with the code below, fixes the it.<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->for ($i=0; $i<count($arr_Multiplier); $i++) {<br />Â Â Â Â $arr_EstimateTotal[$i]['ItemType'] = $arr_Multiplier[$i]['ItemType'];<br />Â Â Â Â $arr_EstimateTotal[$i]['Multiplier'] = 1 + $arr_Multiplier[$i]['Multiplier'];<br />Â Â Â Â for ($j=0; $j<count($arr_Estimate); $j++) {<br />Â Â Â Â Â Â Â Â if ($arr_Multiplier[$i]['ItemTypeID'] == $arr_Estimate[$j]['ItemTypeID']) {<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['ItemTotal'] = $arr_EstimateTotal[$i]['ItemTotal'] + $arr_Estimate[$j]['Total'];<br />Â Â Â Â Â Â Â Â Â Â Â Â $arr_EstimateTotal[$i]['MultTotal'] = ceil($arr_EstimateTotal[$i]['ItemTotal'] * $arr_EstimateTotal[$i]['Multiplier']);<br />Â Â Â Â Â Â Â Â }<br />Â Â Â Â }<br />Â Â Â Â $OverallTotal = $OverallTotal + $arr_EstimateTotal[$i]['MultTotal'];<br />}<!--c2--></div><!--ec2--><!--content-->
Glad you sorted it out. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->