<!--set the center alignment within the table, the table border 2px-->
<table align= "center" border= "2px" ><tr><td><input type= "text" name= "Number1" size=4></td ><td><select name= "Caculate" size= "1" ><option value= "+" >+</option><option value= "-" >-</option><option value= "*" >*</option><option value= "/" >/</option><option Value= "%" >%</option></select></td><td><input type= "text" name= "Number2" size=4> </td><td><input type= "Submit" Name= "OK" value= "calculation" size=4></td> </tr>
Set the first line (input line)
<TR align= "center" >
<!--colspan is used to merge cells to make the output data centered and more aesthetically pleasing. --><TD width= "full" colspan= "4" ><?phpfunction caculate ($numb 1, $numb 2, $method) {switch ($method) {case ' + ' : Return $numb 1+ $numb 2;break;case '-': return $numb 1-$numb 2;break;case ' * ': return $numb 1* $numb 2;break;case '/': return $ numb1/$numb 2;break;case '% ': return $numb 1% $numb 2;break;default:break;}} if (Isset ($_post[' OK ')) {$numb 1=$_post[' number1 '); $numb 2=$_post[' number2 ']; $method =$_post[' caculate '];if (is_ Numeric ($numb 1) &&is_numeric ($numb 2)) {if ($method = = '/' && $numb 2==0) {echo "<script>alert (' The divisor cannot be "0", please re-enter! </script> "; return;} $res =caculate ($numb 1, $numb 2, $method), echo "$numb 1 $method $numb 2 = $res";} Else{echo "<script>alert (' you entered not a number, please re-enter! ') </script> ";}}? ></td></tr>
Set second row (output line)
1<!doctype html>234<meta charset= "Utf-8" >5<title> Web Computers </title>67<style type= "Text/css" >8 h1{9Font-size=24px;TenText-align:Center; Onefont-family: "Blackbody" ; A } - - the</style> -<body> - -<form method= "POST" > +<table align= "center" border= "2px" > -<tr> +<td> A<input type= "text" name= "Number1" size=4> at</td> -<td> -<select name= "Caculate" size= "1" > -<option value= "+" >+</option> -<option value= "-" >-</option> -<option value= "*" >*</option> in<option value= "/" >/</option> -<option value= "%" >%</option> to</select> +</td> -<td> the<input type= "text" name= "Number2" size=4> *</td> $<td>Panax Notoginseng<input type= "Submit" Name= "OK" value= "calculation" size=4> -</td> the</tr> +<TR align= "center" > A<TD width= "full" colspan= "4" > the<?PHP + functionCaculate ($numb 1,$numb 2,$method) - { $ Switch($method) $ { - Case' + ': - return $numb 1+$numb 2; the Break; - Case‘-‘:Wuyi return $numb 1-$numb 2; the Break; - Case‘*‘: Wu return $numb 1*$numb 2; - Break; About Case‘/‘: $ return $numb 1/$numb 2; - Break; - Case‘%‘: - return $numb 1%$numb 2; A Break; + default: the Break; - } $ } the if(isset($_post[' OK '])) the { the $numb 1=$_post[' Number1 ']; the $numb 2=$_post[' Number2 ']; - $method=$_post[' Caculate ']; in if(Is_numeric($numb 1) &&Is_numeric($numb 2)) the { the if($method= = '/' &&$numb 2==0) About { the Echo"<script>alert (' divisor cannot be" 0 ", please re-enter!) ') </script> "; the return; the } + $res=caculate ($numb 1,$numb 2,$method); - Echo"$numb 1 $method $numb 2=$res"; the }Bayi Else the { the Echo"<script>alert (' you entered not a number, please re-enter!") ') </script> "; - } - } the?> the</td> the</tr> the</table> -</form> the the</body> theFull code
php+html Implementing a Web page calculator