2017-05-04 54 views
1

嵌套表格我揣摩如何處理兩個嵌套形式。第一個從select-option下拉菜單發送數據到another_file.php。嵌套的應該從複選框發送數據到當前文件,應該由isset($_POST['...'])處理。這裏是我的簡化代碼:處理的HTML/PHP

if (isset($_POST['a'])) 
     { 
     // do something 
     } 

      if (isset($_POST['b'])) 
     { 
     // do something else 
     } 

     echo "<form action='another_file.php' method='post'>"; // begin of first form 
      echo "<table class ='table table-hover table-condensed table-striped table-bordered'>"; 
      echo "<thead>"; 
      echo "<th>ID</th><th>Jídlo</th><th>Množství</th><th>por_cislo</th><th>Odebrat</th>"; 
      echo "</thead>"; 
      while($rows = $stmt->fetch()){ 

       echo "<tr><td>" . $rows['id'] . "</td><td>".$rows['jidlo']; 
       echo "<select name =".$rows['id']."_".$rows['por_cislo']."> "; 
       $stmt2 = $db->query($q2); 
       echo "<option value ='nic'> (vyberte potravinu) </option>"; 
       $max_por_cislo = $rows['por_cislo']; 
       while($rows2 = $stmt2->fetch()) 
       { 
        echo '<option value="'.$rows2['id'].'">'.$rows2['jidlo'].'</option>'; 
       }; 
       echo "</select>"; 
        echo "</td> <td>" . $rows['mnozstvi'] . "g <input name = '".$rows['por_cislo']."' type='text' value = '-'></td><td>".$rows['por_cislo']."</td>"; 
echo "<td><form action ='this_file.php' method = 'post'>"; // begin of nested form 
     echo "<input type='checkbox' id='atur_peg' name='idecko[]' value=".$rows['id']."*".$rows['por_cislo']." /></td></tr> "; 

      }; 
      echo "<input type='hidden' name='pc' value=".$plan_cislo.">"; 
      echo "<tr><td colspan='2'><input name = 'go' type='submit' value='OK'/></td><td colspan='2'><input type = 'submit' name ='a' value='ADD'/></td>"; 
      echo "<td><input type = 'submit' name ='b' value='DELETE checked'/></form></td></tr>"; // end of nested form 

      echo "</table>"; 
     echo "</form>"; // end of first form 

Is 

有沒有辦法正確地做到這一點?

+0

你因爲'而($行= $ stmt-> fetch()方法)'你將其分配給$ stmt->提取和在這種情況下,同時在你的代碼中的一些錯誤,我認爲...循環永遠不會終止。我並沒有真正明白這個問題,請您詳細說明一下。 – RepeaterCreeper

+0

@RepeaterCreeper你錯了。這件事情能正常工作。顯然這不是我想弄明白的問題...... – DRINK

回答

0

代替嵌套形式,使用jQuery來檢測複選框被檢查,然後改變其形式行動URL。這條線上的東西..你將不得不修改相同的,以滿足您的需求。

$(document).ready(function(){ 
$("#formname").on("change", "input:checkbox", function(){ 
    if($(this).is(":checked")) { 
     $('#formName').attr('action', 'this_file.php'); 
     $("#formname").submit(); 
    } 

}); 

});