Калкулатор

razbiva4

Registered
За този урок ще са ни нужни 2 файла : calculator.css И calculator.php .
Да започваме:

първо с calculator.css :

Код:
 }
a:link
{
	text-decoration: none;
	color: #000000;font-size:10pt 
}
a:visited
{
	text-decoration: none;
	color: #000000;font-size:10pt 
} 
a:active 
{
	text-decoration: none;
	color: #000000;font-size:10pt
}
a:hover {
	text-decoration: underline;
	color: #000000;font-size:10pt
} 
body
{
	font-size: 10pt; font-family: Verdana; vertical-align: baseline;
	background-color: #FFFFFF;
	color: #000000;
	SCROLLBAR-BASE-COLOR: #FFFFFF;
	SCROLLBAR-ARROW-COLOR: #000000;
}
table
{
	font-size: 10pt; font-family: Verdana; vertical-align: baseline;
	table-border-color-light: #000000;
	table-border-color-dark: #000000; 
}
cell
{
	font-size: 10pt; font-family: Verdana; vertical-align: baseline;
	cell-border-color-light: #000000;
	cell-border-color-dark: #000000; 
}
h1, h2, h3, h4, h5, h6
{
	font-family: Verdana, Helvetica; color:#000000
}
h1
{
	font-size:18pt; font-weight:bold
}
h2
{
	font-size:16pt; font-weight:bold
}
h3
{
	font-size:14pt; font-weight:bold 
}
h4
{
	font-size:12pt; font-weight:bold
}
h5
{
	font-size:10pt; font-weight:bold
}
h6
{
	font-size:8pt; font-weight:bold
}
SELECT       	
{
	font-family:Verdana;font-size:10pt;background:#FFFFFF;color:#000000;
}
INPUT
{
    font-family:Verdana;font-size:10pt;background:#FFFFFF;color:#000000;
}
TEXTAREA     	
{
	font-family:Verdana;font-size:10pt;background:#FFFFFF;color:#000000;
}
hr				{color: #000000; background-color: #FFFFFF; height: 1px; width: 50%;}
Готови сме с визията на каалкулатора.
Сега да минем към него самия calculator.php :
Код:
<?php
function square( $number )
{
$newNumber = $number * $number;
return
$newNumber;
}
function cube( $number )
{
$newNumber = $number * $number * $number;
return
$newNumber;
}
?>
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="calculator.css">
<title>Calculator</title>
</head>

<body>
<div align="center">
  <center>
<form method="POST" action="calculator.php">
<p><b>prosto pishete 2-te 4isla v polencata i natiscate funkciqta koqto iskate
da bade izvarshena ;)</b><br><br>
</p>
<table border="0" cellspacing="1" width="304" id="calculator" height="139">
  <tr>
    <td width="292" align="center" height="39">
    <h3> Calulator</h3>
    </td>
  </tr>
  <tr>
    <td width="292" align="center" height="23">
    <input type="text" name="this" size="10"><br>    <input type="text" name="that" size="10"></td>
  </tr>
  <tr>
    <td width="292" align="center" height="24">
    <input type="submit" value="+" name="do">
    <input type="submit" value="-" name="do">
    <input type="submit" value="*" name="do">
    <input type="submit" value="/" name="do"><br>
    <input type="submit" value="^2" name="do">
    <input type="submit" value="^3" name="do">
    <input type="submit" value="SqRt" name="do"> 
    </td>
  </tr>
<?php

if ($do == "+"){
	if (($_POST['this'] != "") && ($_POST['that'] != "")) {
	$result = $_POST['this'] + $_POST['that'];
	}
	else {
	$message = "<font color=\"red\">You did not fill in both fields!</font>";
	$result = "N/A";
	}
}
elseif ($do == "-"){
	if (($_POST['this'] != "") && ($_POST['that'] != "")) {
	$result = $_POST['this'] - $_POST['that'];
	}
	else {
	$message = "<font color=\"red\">You did not fill in both fields!</font>";
	$result = "N/A";
	}
}
elseif ($do == "*"){
	if (($_POST['this'] != "") && ($_POST['that'] != "")) {
	$result = $_POST['this'] * $_POST['that'];
	}
	else {
	$message = "<font color=\"red\">You did not fill in both fields!</font>";
	$result = "N/A";
	}
}
elseif ($do == "/"){
	if (($_POST['this'] != "") && ($_POST['that'] != "")) {
	$result = $_POST['this'] / $_POST['that'];
	}
	else {
	$message = "<font color=\"red\">You did not fill in both fields!</font>";
	$result = "N/A";
	}
}
elseif ($do == "^2"){
	if ($_POST['this'] != "") {
	$result = square ( $_POST['this'] );
	$that = "";
	}
	else {
	$message = "<font color=\"red\">You did not fill in the first field!</font>";
	$result = "N/A";
	}
}
elseif ($do == "SqRt"){
	if ($_POST['this'] != "") {
	$result = sqrt($_POST['this']);
	$that = "";
	}
	else {
	$message = "<font color=\"red\">You did not fill in the first field!</font>";
	$result = "N/A";
	}
}
elseif ($do == "^3"){
	if ($_POST['this'] != "") {
	$result = cube ( $_POST['this'] );
	$that = "";
	}
	else {
	$message = "<font color=\"red\">You did not fill in the first field!</font>";
	$result = "N/A";
	}
}
?>

  <tr>
    <td width="292" align="center" height="19"><br><b>Result: <?php echo($result); ?><br><?php echo($message); ?></b></td>
  </tr>
  <tr>
    <td width="292" align="center" height="19"><br>Powered by
	<a href="http://ar3na.no-ip.info">Arena™</a></td>
  </tr>
</table>
</form>
  </center>
</div>
</body>

</html>
И сме готови :) надявам се да ви хареса. :D
 
Smirnoff каза:
:arrow: http://scripts.ringsworld.com/calculators/calculator/calculator.php.html

Ето го човека който се е прецакал :wink:
мхм.. то няма нищо че урока е преписан, нали отдолу пише Powered by Arena TM ? Това е най-важното :wink:
 

Горе