- Original Poster
- #1
I'm trying to put a simple calculation function on a page. I've used PHP calculator code I found here, and modified this to do the calculation I need: First Number² x Second Number.
What I'm struggling with is deleting of an unnecessary bit of text - "Operation" with a drop-down list (limited to one option) - that I don't want to include on the page - there won't be an option to choose anything other than the necessary calculation.
If I take out the code that puts this on the page
the calculation won't run.
The full code is included on http://employmentlawclinic.com/attendance-and-performance/test-page-2/
I don't really understand PHP, so is anyone handy on it that can tell me how to tidy up this code?
Thanks,
Karl Limpert
What I'm struggling with is deleting of an unnecessary bit of text - "Operation" with a drop-down list (limited to one option) - that I don't want to include on the page - there won't be an option to choose anything other than the necessary calculation.
If I take out the code that puts this on the page
Code:
Operation:
<select name="oper">
<option value="multiply">Multiplication</option>
</select>
The full code is included on http://employmentlawclinic.com/attendance-and-performance/test-page-2/
Code:
<?php
class calc {
var $number1;
var $number2;
function multiply($number1,$number2)
{
$result =$number1 * $number1 * $number2;
if ($result > 649)
echo "Your worker's Bradford Factor is $result, and requires urgent attention. Call us now on 020 3397 297 for assistance & advice on managing your sick leave.<br><br>";
elseif ($result > 399)
echo "Your worker's Bradford Factor is $result, and you providing you have given earlier warnings, you should be considering a final written warning at this stage. Call us now on 020 3397 297 for assistance & advice on managing your sick leave.<br><br>";
elseif ($result > 124)
echo "Your worker's Bradford Factor is $result, and you should be considering issuing formal written warnings. Call us now on 020 3397 297 for assistance advice on managing your sick leave. <br><br>";
elseif ($result > 49)
echo "Your worker's Bradford Factor is $result, and you should be considering issuing formal written warnings. Call us now on 020 3397 297 for assistance & advice on managing your sick leave.<br><br>";
elseif ($result > 0)
echo "Your worker's Bradford Factor is $result; everyone gets sick on occasion, but there doesn't appear to be much that should concern you with this absence. Call us now on 020 3397 297 for assistance & advice on managing your sick leave<br><br>";
}
}
//Creating object of class
$calc = new calc();
?>
<form name="calc" action="" method="POST">
<p>How many times has the worker being off sick?</p> <input type="text" name="value1"><br>
<p>And how many sick days have they had in total?</p> <input type="text" name="value2"><br>
Operation:
<select name="oper">
<option value="multiply">Multiplication</option>
</select>
<br>
<input type="submit" value="Calculate Your Worker's Bradford Factor" name="submit">
</form>
<br>
<br>
<?php
if($_POST['submit']){
$number1 = $_POST['value1'];
$number2 = $_POST['value2'];
$oper = $_POST['oper'];
if(!eregi("[0-9]", $number1)){
echo "<font color='red'>The total occasions of sick leave must be a number</font>";
}
if(!eregi("[0-9]", $number2)){
echo "<font color='red'>The total sick days must be a number</font>";
}
if($oper == "multiply"){
$calc->multiply($number1,$number2);
}
}
?>
<?php
if($_POST['submit1']){
$number = $_POST['value'];
$operat = $_POST['operat'];
if(!$number){
echo "<font color='red'>Please enter number in calculator 2</font>";
}
}
?>
I don't really understand PHP, so is anyone handy on it that can tell me how to tidy up this code?
Thanks,
Karl Limpert