繁体   English   中英

在PHP的while循环中更新多个日期列

[英]Update Multiple date column in while loop in PHP

仅具有一个日期列的表格需要更新。 但是我无法在表格上填写其他日期。

html / php表单代码如下:

<td><form id="form2" name="form2" method="post">
  <table  width="100%" >
    <tr><td colspan="10" align="left"><h3>Container Details</h3>
        </td></tr>enter code here
    <tr>
      <td><table  width="100%" >
        <tr>
          <td><strong>CONTAINER NO</strong></td>
          <td><strong>CONTAINER SIZE</strong></td>
          <td><strong>CONTAINER CATEGORY</strong></td>
          <td><strong>IGM NO.</strong></td>
          <td><strong>LINE NO.</strong></td>
          <td><strong>BOE NO.</strong></td>
          <td><strong>GATE IN DATE</strong></td>
          <td><strong>EXPECTED DELIEVRY DATE</strong></td>
          <td><strong>GATE OUT DATE</strong></td>

        </tr>
    <?php 
    $i=0;
        while($r = mysqli_fetch_row($res)){
        ++$i;
        ?>
        <tr>
          <td><input type="hidden" name="vci_no[]" id="vci_no" value="<?php echo @$r['0']; ?>"><?php echo @$r[1]; ?></td>
          <td><?php echo @$r[2]; ?></td>
          <td><?php echo @$r[3]; ?></td>
          <td><?php echo @$r[4]; ?></td>
          <td><?php echo @$r[5]; ?></td>
          <td><?php echo @$r[6]; ?></td>
          <td><?php echo ((date('d-m-Y', strtotime($r['7']))==date('d-m-Y', strtotime('')))?"":date('d-m-Y', strtotime($r[7]))); ?></td>
          <td><input type='text' name='gateout_plnd_dt[]' value='<?php echo((date('d-m-Y', strtotime($r[8]))==date('d-m-Y', strtotime('')))?"":date('d-m-Y', strtotime($r[8]))) ?>'  class='dt' id="gateout_plnd_dt<? echo $r[0]; ?>"/>
         </td><input type="submit" name="save" id="save" value="Update" onClick="return validateUpdateWo()">

更新的代码:

if(isset($_REQUEST['save'])){   
     $gateout_plnd_dt = $_REQUEST['gateout_plnd_dt'];
    $vci_no = $_REQUEST['vci_no'];
    echo sizeof($vci_no);echo sizeof($gateout_plnd_dt);

    for($i=0; $i<sizeof($vci_no); $i++){


      mysqli_query($con, "update veh_cont_import set gateout_plnd_dt= '".date('Y-m-d', strtotime(urlencode($gateout_plnd_dt[$i])))."'
                           where vci_no = '".mysqli_real_escape_string($con, $vci_no[$i])."'") or die(mysqli_error($con));
    }

我无法在第一个列中选择任何日期。

屏幕截图

我也尝试过通过PHP为输入类型传递不同的id,但结果相同,如下所示:

id="gateout_plnd_dt<? echo $r[0]; ?>"

完全是其他答案,

命名如下:

  • gateout_plnd_dt [1]
  • gateout_plnd_dt [2]
  • gateout_plnd_dt [n]

然后数组将具有索引,然后您可以使用php检查不为空的索引

$array = filter_input(INPUT_POST,'gateout_plnd_dt');
foreach($array as $key => $item){
      if(strlen($item) > 0){ 
          echo "$key has the value $item" . PHP_EOL;
      }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM