|
|
Php Calculator - Simple but cool. | ||
Discussion by maddog39 with 21 Replies.
Last Update: October 7, 2011, 7:30 am ( View Rated (1) ) | |||
![]() |
|
|
I was eally bored the other day. So I decided to make a php calculator just out of the blue. I set it up and it works really good. You can see mine here. Ill give you guys the source code too if you want it. Here it is...
Name this calculate_forum.html
CODE
<html>
<head>
<title>Calculation Form</title>
</head>
<body>
<form method="post" action="calculate.php">
<p>Value 1: <input type="text" name="val1" size="10"></p>
<p>Value 2: <input type="text" name="val2" size="10"></p>
<p>Calculation:<br>
<input type="radio" name="calc" value="add"> add<br>
<input type="radio" name="calc" value="subtract"> subtract<br>
<input type="radio" name="calc" value="multiply"> multiply<br>
<input type="radio" name="calc" value="divide"> divide</p>
<p><input type="submit" name="submit" value="Calculate"></p>
</body>
</html>
Name this calculate.php
CODE
<?php
if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) {
header("Location: calculate_form.html");
exit;
}
if ($_POST[calc] == "add") {
$result = $_POST[val1] + $_POST[val2];
} else if ($_POST[calc] == "subtract") {
$result = $_POST[val1] - $_POST[val2];
} else if ($_POST[calc] == "multiply") {
$result = $_POST[val1] * $_POST[val2];
} else if ($_POST[calc] == "divide") {
$result = $_POST[val1] / $_POST[val2];
}
echo "<title>Calculation Result</title>";
echo "<p>The result of the calculation is: $result</p>";
echo "<p><a href=\"calculate_form.html\" target=\"_self\">Do Another</a></p>";
?>
Then upload the files to your server and go to www.yourdomain.com/calculate_form.html and enter 1 number in variable 1 and another number in variable 2. Then select a mathmatical method, then press calculate and then your answer will pop-up in a new page. The just click 'Do Another' to do another problem. Comments are appreciated.
QUOTE (maddog39)
Hello all,I was eally bored the other day. So I decided to make a php calculator just out of the blue. I set it up and it works really good. You can see mine here. Ill give you guys the source code too if you want it. Here it is...
Name this calculate_forum.html
CODE
<html>
<head>
<title>Calculation Form</title>
</head>
<body>
<form method="post" action="calculate.php">
<p>Value 1: <input type="text" name="val1" size="10"></p>
<p>Value 2: <input type="text" name="val2" size="10"></p>
<p>Calculation:<br>
<input type="radio" name="calc" value="add"> add<br>
<input type="radio" name="calc" value="subtract"> subtract<br>
<input type="radio" name="calc" value="multiply"> multiply<br>
<input type="radio" name="calc" value="divide"> divide</p>
<p><input type="submit" name="submit" value="Calculate"></p>
</body>
</html>
Name this calculate.php
CODE
<?php
if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] =="")) {
header("Location: calculate_form.html");
exit;
}
if ($_POST[calc] == "add") {
$result = $_POST[val1] + $_POST[val2];
} else if ($_POST[calc] == "subtract") {
$result = $_POST[val1] - $_POST[val2];
} else if ($_POST[calc] == "multiply") {
$result = $_POST[val1] * $_POST[val2];
} else if ($_POST[calc] == "divide") {
$result = $_POST[val1] / $_POST[val2];
}
echo "<title>Calculation Result</title>";
echo "<p>The result of the calculation is: $result</p>";
echo "<p><a href=\"calculate_form.html\" target=\"_self\">Do Another</a></p>";
?>
Then upload the files to your server and go to www.yourdomain.com/calculate_form.html and enter 1 number in variable 1 and another number in variable 2. Then select a mathmatical method, then press calculate and then your answer will pop-up in a new page. The just click 'Do Another' to do another problem. Comments are appreciated.
I just tried it , it was fun.
but there are others where u dont have seperates boxes for each value, i assuma u know php and u know how to use {echo} etc.
That's a good once.
It's a very simple, yet usefull program
but in my opinion,
using php to make a calculator,is not quite efficient.
PHP has to post/GET the data,then display the result,
but JAVASCRIPT can display the result without POST/GET action.
JAVASCRIPT is faster in doing these.
LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.
QUOTE (Xedos)
LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.Well, if you use JavaScript it will be fast. Really fast, because all the calculation happens server-side. With this calculator you don't have to use PHP, because you don't have to do anything that requires the server's capabilities.
Why have the visitor go to the page, fill out the form, send it to the server and then wait for the server to send a reply when you can have the visitor go to the page and fill out the form.
If you are learning PHP and want to do things like this, that's okay, but the better solution would be to use JavaScript (which isn't at all as complex as PHP is).
The basics are easy though, but it gets harder once you want better programs.
But, once you know PHP, it's the best scripting language, if you ask me.
(Partly because it doesn't take up that much resources
QUOTE (Xedos)
LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.YES!
but not to do such a thing.
QUOTE (Xedos)
Nice, simple, useful program.LuciferStar: Why do you think javascript is better? PHP is much more powerful and much more easy to learn.
yes, php is much more simply, but javascript is faster. The javascript code are load in the HTML page, and when it's done, you click on the button 'Calculate' and the result come at the same time. PHP needs to load an other page, an go back to another calc, and load the page again....
we may conside that many things can be solved by many different ways.
What we may do is try to find the best neat path.
BTW,
PHP,JSP,ASP are server-side scripts,
Javascript,vbscript are client-side scripts.
http://www.trap17.com/forums/Js-Calculator-t7499.html
Php Calculator
I just checkout the calculator posted here by someonein in javascript ..
But the problem is that it is showng the opreator in the text field also.
So can any one send the code of calculator which dnt shw the operator in the text field and havn only the single text field
-question by tarundeep singh
The front-end HTML code for my PHP | Calculator is the same as yours but my back-end PHP scripting code differs a little from yours. This is what it I have. What mazes me is that I am not able to successfully run the script, thus, ending up with the PHP parser annoying me with its tedious error scripts. Please, try and help me out if you can. Thank you! :-)
[/font]
[php]
<?php
if (($_POST[Value-1] = "") || ($_POST[Value-2] = "") || ($_POST[Calc] =""))
{
header("Location: caculator.html");
exit;
}
if ($_POST[Calc] == "Add")
{
$result = $_POST[Value-1] + $_POST[Value-2];
}
else if ($_POST[Calc] == "Subtract")
{
$result = $_POST[Value-1] - $_POST[Value-2];
}
if ($_POST[Calc] == "Divide")
{
$result = $_POST[Value-1] / $_POST[Value-2];
}
else if ($_POST[Calc] == "Multiply")
{
$result = $_POST[Value-1] * $_POST[Value-2];
}
?>
<html>
<head>
<title>
PHP | Calculator
</title>
</head>
<body>
<div align="center">
<p>The result of the computation was
<?php
echo ("$result");
?>
</p>
<a href="calculator.html">Back</a >
</div>
</body>
</html>
[/php]
It only has one numerical input field I should think it would take someone who knows how under 10 mins to create the code which I would just want to paste into the wordpress page...
The customer types in a number (relating to years in this case)
i.e
Over ____ Years
and then then hits CALCULATE.
Answer ___________
The no. of years must then be multiplied by £1500 with an additional £1500 being added on top. i.e 10 years = £16,500
Let me know if you feel you can help...
CODE
<?PHP$result=$_POST['day'];
$pv=$_POST['pv'];
$av=$_POST['av'];
$rr=$_POST['rr'];
$no=$_POST['no'];
$tt=$_POST['tt'];
$downtime=$_POST['downtime'];
if(!$_POST['day'])
{
echo '
<form method="post" action="'.$_SERVER['PHP_SELF'].'">
<select name="day">
<option value="mon">Monday</option>
<option value="tue">Tuesday</option>
<option value="wed">Wednesday</option>
<option value="thu">Thursday</option>
<option value="fri">Friday</option>
<option value="sat">Saturday</option>
<option value="sun">Sunday</option>
</select><br />
<td>Planned Volume:</td>
<input type="text" name="pv" size="5"><br />
<td>Actual Volume:</td>
<input type="text" name="av" size="5"><br />
<td>Reject/Rework:</td>
<input type="text" name="rr" size="5"><br />
<td>Nett Output</td>
<input type="text" name="no" size="5"><br />
<td>Takt Time</td>
<input type="text" name="tt" size="5"><br />
<td>Downtime</td>
<input type="text" name="downtime" size="5"><br />
<input type="submit" name="doit" value="calculate">
</form>
';
}else{
if($_POST['day'] == 'mon')
{
echo 'Your working hour is 495min';
$result=495 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
if($_POST['day'] == 'tue')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
if($_POST['day'] == 'wed')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
if($_POST['day'] == 'thu')
{
echo 'Your working hour is 505min';
$result=505 - $downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
if($_POST['day'] == 'fri')
{
echo 'Your working hour is 430min';
$result=430-$downtime;
availability($result);
performance($not, $tt, $av, $result);
quality($no, $av);
oee($count2, $count4, $count7);
}
}
function availability($result){
$count2= $result / $ppt;
$count3= $count2 * 100;
$count = number_format($count3, 0);
echo 'Availability percentage is'. "$count" . "%";
}
function performance($not, $tt, $av, $result){
$not = $av / $result;
$count4= $not / $tt;
$count5= $count4 * 100;
$count6= number_format($count5, 0);
echo 'Performance percentage is'. "$count6" . "%";
}
function quality($no, $av){
$count7= $no / $av;
$count8= $count7 * 100;
$count9= number_format($count8, 0);
echo 'Quality percentage is'. "$count9" . "%";
}
function oee($count2, $count4, $count7){
$count10= $count2 * $count4 * $count7;
$count11= $count10 * 100;
$count12= number_format($count11, 0);
echo 'OEE percentage is'. "$count12" . "%";
}
?>
Similar Topics:
Php Formmail Generator
Making Calculators with PHP
Cool Php And Sql Books?
Php Designer 2005 - By Far The Best One.. .. that was the description.. (13)
|
(9) New Php Forums!
|
Loading...
HOME 






