使用已根据先前条件显示的表单的输出进行计算

时间:2016-07-04 22:42:07

标签: php html

我正在为正在运行的步速计算器编写代码,如果有任何风,你可以选择将其计算在计算中,根据它是逆风还是顺风来改变时间

HTML的一部分:

$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/>";
}

PHP SCRIPT:

因此PHP的这部分工作,它创建所有字段,其中包含我需要的值来计算在逆风顺风中丢失/获得的速度:

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>";

    }   

但是,当我尝试使用它来改变输出表中的速度时。它只读取标题标题,它没有达到echo TEST值,所以我知道它与第二个if / elseif语句或设置风向后有关。

{{1}}

1 个答案:

答案 0 :(得分:0)

我不是PHP,但是WindDirection的value属性中没有问题?在值中你可能有'逆风/尾风X'但你的if语句试图将它与'逆风/尾风'进行比较。不确定哪一个是正确的,但您需要执行以下操作之一

  • 更改选项元素的值属性
  • 更改if语句以与'Headwind / Tailwind $ counter'进行相等比较或基于'startsWith'逻辑

无论如何,在开始时你可以尝试在if语句之前回显$ direction以找出真正的价值。