2017-05-04 60 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(); 
    } 

}); 

});