PHP - Please Help With Php Maths
Hi,
I am using PHP to perform some area calculations. I have created this form to collect the values: Code: [Select] <form name="form1" method="post" action="<?php htmlentities($_SERVER['PHP_SELF']); ?>"> <table width="100%" border="0" cellspacing="0" cellpadding="8"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="1"> <tr> <td bgcolor="#666666"><table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td align="center" bgcolor="#3471C6" class="fondoHogartec"><?=CNT_TXT_CALCULATORTITLE?></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_WATERLINE?><br> </span> <input name="waterline" type="text" class="CalculatorFieldTXT" id="waterline" value="<?php echo((isset($_POST["waterline"]))?$_POST["waterline"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_BEAM?></span><br> <input name="beam" type="text" class="CalculatorFieldTXT" id="beam" value="<?php echo((isset($_POST["beam"]))?$_POST["beam"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_DRAUGHT?></span><br> <input name="draught" type="text" class="CalculatorFieldTXT" id="draught" value="<?php echo((isset($_POST["draught"]))?$_POST["draught"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoPrecio"><?=CNT_TXT_SURFACE?><br> </span> <input name="surface" type="text" class="CalculatorFieldTXT" id="surface" value="<?php echo $total_surface ?>" size="10" > </label></td> </tr> <tr> <td align="center" nowrap bgcolor="#EEEEDD"><label class="CarritoPrecio"><?=CNT_TXT_TOTALCANS?><br> </label> <input name="cans_needed_2coats" type="text" class="CalculatorFieldTXT" id="cans_needed_2coats" value="<?php echo $total_cans ?>"> <br></td> </tr> <tr> <td align="center" nowrap bgcolor="#EEEEDD"><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td colspan="3" align="center" class="TitulosTXT2"><?=CNT_TXT_KEELTYPE?></td> </tr> <tr> <td align="center" class="TitulosTXT2"><label> <input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_LONG?>"> </label></td> <td align="center"><input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_BILGE?>"></td> <td align="center"><input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_FIN?>"></td> </form>and this is the PHP to perform the calculations: Code: [Select] // INICIATE CALCULATOR $keeltype = $_POST["keel_type"]; $waterline_length = $_POST["waterline"]; $beam = $_POST["beam"]; $draught = $_POST["draught"]; if ($keeltype == CNT_TXT_LONG) { $total_surface = $waterline_length*($beam+$draught) ; } if ($keeltype == CNT_TXT_BILGE) { $total_surface = ($waterline_length*($beam+$draught))* 0.75 ; } if ($keeltype == CNT_TXT_FIN) { $total_surface = ($waterline_length*($beam+$draught))* 0.50 ; } $total_cans = $total_surface / 25 ; // END CALCULATOR It works fine when the values entered in the form contain decimals separated by "." but it doesn't calculate properly when the decimals are separated by a comma. Please help. Thanks. Similar TutorialsHi All, I am trying to work out some simple maths between 2 numbers, that are returned in variables - say $v1 and $v2. $v2 = 126 and $v1 = 318 I can do the working out - $total = $v2 / $v1 * 100 However is there any way that I can set total to only display the first 2 numbers? Just that I am getting a long result cause of the decimal places. (39.62264150943396..........) Can it be done? Thanks Matt Hi if ive made a variable how do i tell it to be less than or equal to another variable ? currently im using $lowhigh_price = ( <= 0.75 * $av_price); but it tells me there is something wrong hlep please This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350117.0 |