2016-07-04 40 views
1

我正在爲跑步速度計算器編寫代碼,如果有任何風,您可以選擇將此因子計入計算中,從而改變時間上如果逆風或順風HTML的使用基於以前的條件已經出現的表單的輸出進行計算

部分:

<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腳本:

所以PHP的這一部分工作,它創建了所有與我需要的值的字段計算在逆風順風中失去/增加的速度:

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

但是,當我嘗試使用它來改變輸出表中的速度。它只讀取標題標題,未達到回顯TEST值,因此我知道它與第二個if/elseif語句或風向設置後有關。

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

    } 
+0

您的輸入是否符合if語句的條件?通過在頁面上回應那些你會認出的東西來測試。然後用某種類型的字符串連接包裝windspeed值變量,並查看它的值,如果它爲空可能是問題 – Jeff

回答

0

我不是PHP,但不是你的WindDirection的值屬性的問題?在你可能有'逆風/ Tailwind X'的價值,但你的if語句試圖比較'逆風/尾風'。不知道其中哪些是正確的,但你需要做以下

  • 更改您的選項元素
  • 更改if語句做「逆風/順風$計數器」或基於平等比較的價值屬性之一on'startsWith'邏輯

無論如何,在開始時您可以嘗試在if語句之前回顯$ direction以找出實際值。