Php 使用基于先前计算条件已出现的窗体的输出
我正在为一个跑步速度计算器编写代码,如果有风,你可以选择将其考虑到你的计算中,根据是逆风还是顺风改变时间 HTML的一部分:Php 使用基于先前计算条件已出现的窗体的输出,php,html,Php,Html,我正在为一个跑步速度计算器编写代码,如果有风,你可以选择将其考虑到你的计算中,根据是逆风还是顺风改变时间 HTML的一部分: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="checkbox" id="windspeed" name="windspeed" value="windspeed"> <label for="windspeed">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST">
<input type="checkbox" id="windspeed" name="windspeed" value="windspeed">
<label for="windspeed">Any Wind?</label></p>
我不喜欢PHP,但WindDirection的value属性不是有问题吗?在值中,您可能有“逆风/顺风X”,但您的if语句试图将其与“逆风/顺风”进行比较。不确定以下哪项是正确的,但您需要执行以下操作之一
- 更改选项元素的值属性
- 将if语句更改为与“Headwind/Tailwind$counter”或基于“startsWith”逻辑进行相等比较
无论如何,在开始时,您可以尝试在if语句之前回显$direction,以找出真正的值。我不喜欢PHP,但WindDirection的value属性不是问题所在吗?在值中,您可能有“逆风/顺风X”,但您的if语句试图将其与“逆风/顺风”进行比较。不确定以下哪项是正确的,但您需要执行以下操作之一
- 更改选项元素的值属性
- 将if语句更改为与“Headwind/Tailwind$counter”或基于“startsWith”逻辑进行相等比较
无论如何,在开始时,您可以尝试在if语句之前回显$direction,以找出实际值。您的输入是否符合该if语句的条件?通过回显页面上可以识别的内容来测试。然后用某种字符串连接方式包装windspeed值变量,并查看其值是否为null,这可能是问题所在。您的输入是否满足if语句的条件?通过回显页面上可以识别的内容来测试。然后用某种字符串连接方式包装windspeed值变量,并查看其值是否为null,这可能是问题所在
$max=($_POST['distance']/$_POST['laplength']);
if (!empty($_POST['windspeed'])&&(empty($_POST['elevation'])))
{
echo "<p><label for=\"Windspeedvalue\">Wind Speed (mph): </label>
<input type=\"number\" id=\"Windspeedvalue\" name=\"Windspeedvalue\"></p> <br/>
<label for=\"height\">Height(cm):</label><input type=\"number\" id=\"height\" name=\"height\"></p><br/>
<label for=\"weight\">Weight(Kg):</label><input type=\"number\" id=\"weight\" name=\"weight\"></p><br/>";
$counter=1;
while($counter<=$max)
{
if (!empty($_POST['windspeed'])&&(empty($_POST['elevation'])))
{
echo "<br/>
<label for=\"WindDirection\">Lap $counter:</label>
<select name=\"WindDirection\">
<option value=\"\">Wind Direction...</option>
<option value=\"Tailwind $counter\">Tailwind</option>
<option value=\"Headwind $counter\">Headwind</option>
</select>";
$counter++;
}
echo"<input type=\"hidden\" name=\"Winddirectionhidden\" value=\"Winddirectionhidden\"><br/>";
}
echo "<br/>";
}
elseif (!empty($_POST['windspeed'])&&(!empty($_POST['elevation'])))
{
echo "<p><label for=\"Windspeedvalue\">Wind Speed (mph): </label>
<input type=\"number\" id=\"Windspeedvalue\" name=\"Windspeedvalue\"></p><br/>
<label for=\"height\">Height(cm):</label><input type=\"number\" id=\"height\" name=\"height\"></p><br/>
<label for=\"weight\">Weight(Kg):</label><input type=\"number\" id=\"weight\" name=\"weight\"></p><br/>";
}
if (!empty(($_POST['Windspeedvalue'])&&($_POST['Winddirectionhidden'])))
{
$max=$_POST['distance']/$_POST['laplength'];
$totalseconds=($_POST['minutes']*60)+($_POST['seconds']);
$paceinseconds=$totalseconds/$max;
$maxint=(integer)$max;
$pacelost=$_POST['Windspeedvalue']*$_POST['Height']*$_POST['Weight']*1.275;
$pacegained=$_POST['Windspeedvalue']*$_POST['Height']*$_POST['Weight']*(1.275/2);
$totalflattime=$totalseconds-$pacelost+$pacegained;
$flattimeperlap=$totalflattime/$_POST['distance'];
$laptimeinheadwind=$flattimeperlap-($pacelost/$_POST['distance']);
$laptimeintailwind=$flattimeperlap+($pacegained/$_POST['distance']);
echo "<table>";
echo "<tr><th>Lap Number</th><th>Time</th></tr>";
for($counter=1;$counter<=$maxint;$counter++)
{
if(isset($_POST['WindDirection']))
{
$tempperunitseconds=$unitpace*$counter;
$tempminutes=($tempperunitseconds/60);
$outminutes=(integer)$tempminutes;
$outseconds=(integer)(($tempminutes-$outminutes)*60);
printf("<tr><td>%02s</td><td>%02s.%02s</td></td>",$counter,$outminutes,$outseconds);
}
$direction=$_POST['WindDirection'];
if($direction=="Headwind")
{
echo 'TEST1';
$tempperunitseconds=$laptimeintailwind*$counter;
$tempminutes=($tempperunitseconds/60);
$outminutes=(integer)$tempminutes;
$outseconds=(integer)(($tempminutes-$outminutes)*60);
printf("<tr><td>%02s</td><td>%02s.%02s</td></td>",$counter,$outminutes,$outseconds);
}
elseif($direction=="Tailwind")
{
echo 'TEST2';
$tempperunitseconds=$laptimeinheadwind*$counter;
$tempminutes=($tempperunitseconds/60);
$outminutes=(integer)$tempminutes;
$outseconds=(integer)(($tempminutes-$outminutes)*60);
printf("<tr><td>%02s</td><td>%02s.%02s</td></td>",$counter,$outminutes,$outseconds);
};
}
echo "</table>";
}