2013-02-25 110 views
0

我在网上看过,但所有的$ _POST和$ _GET的例子是文本不是数字。 这不是连接到数据库。它不需要表单验证。这只是在我的系统上本地运行的单个页面项目。我想尽可能保持简单。付费率计算器

目标是获得一个输入,您可以在其中输入小时工资。例如15. 然后,当您按下提交的帖子回到同一页面,并列出您每天,每周,每月和每年制作的精彩列表。

任何帮助将不胜感激。

<p>Input your Hourly Pay</p> 
<form method="GET" action="" > 
<input name="num1" type="text" > 
<input type="submit" name="submit" value="Submit"> 
</form> 


<?php 

if ($_GET['num1']) { 
    $rate = $_GET['num1']; 
    return $rate; 
}  

$result_day= $rate * 8; 
$result_week = $rate * 8 * 5; 
$result_month = $rate * 8 * 5 * 4; 
$result_year = $rate * 8 * 5 * 4 * 12; 

echo "Rate: " . $rate . "<br>"; 
echo "Daily: " . $result_day . "<br>"; 
echo "Weekly: " . $result_week . "<br>"; 
echo "Monthly: " . $result_month . "<br>"; 
echo "Yearly: " . $result_year . "<br>"; 

?> 
+0

您只需要一页显示“在这里工作不够” - 无脚本参与! – 2013-02-25 06:51:27

+0

你可以用Javascript来做到这一点。你甚至不需要提交按钮。您甚至可以添加能够输入Rate,Dailt,Weekly ...值的功能,其他功能可以更新。 – 2013-02-25 07:05:39

回答

0

我做了一些修正,但计算仍然是原来的:

<?php 

if (isset($_GET['num1'])) { 
    $rate = $_GET['num1']; 

$result_day= $rate * 8; 
$result_week = $result_day * 5; 
$result_month = $result_week * 4; 
$result_year = $result_month * 12; 

echo "Rate: " . $rate . "<br>"; 
echo "Daily: " . $result_day . "<br>"; 
echo "Weekly: " . $result_week . "<br>"; 
echo "Monthly: " . $result_month . "<br>"; 
echo "Yearly: " . $result_year . "<br>"; 

}else{ 
echo "Please enter your rate!"; 
} 
+0

谢谢!这是完美的。 – starcorelabs 2013-02-25 17:04:45

0

使用onchange事件的JavaScript上的任何字段。然后,您可以使用Javascript来计算其余的值并更新这些字段。

不需要PHP。没有时间滞后,需要一个新的页面。用户会喜欢它。

+0

谢谢你的建议。如果我更了解它,我会试着用JavaScript重写这个项目。目前我正在学习PHP,并认为这将是一个简单的项目。在PHP之后,我将深入研究JS和jQuery。 – starcorelabs 2013-02-25 18:46:47