数组更新乘法结果有问题


something wrong with array updating multiply results

我有一个包含10条记录和2个输入的表。我为它和使用数组,但我做错了什么,但不能弄清楚。我想做的是一次更新许多行!我还在学习php数组

文章

    if($source == 'hoursDayNight'){
    $value      = htmlentities($_POST['value'], ENT_QUOTES, "UTF-8");
    $workcid      = htmlentities($_POST['workcid'][$i], ENT_QUOTES, "UTF-8");
    $worknight      = htmlentities($_POST['worknight'][$i], ENT_QUOTES, "UTF-8");
    $workday      = htmlentities($_POST['workday'][$i], ENT_QUOTES, "UTF-8");
    include('inc.php');     
    //$current_dateedit = date('Y-m-d == H:i:s');
    $current_dateedit = date('Y-m-d');
$i=NULL;
$i=1;
    $queryie = "UPDATE works SET workday='".$workday[$i]."', worknight='".$worknight[$i]."', type='1'  WHERE id='" . $workcid[$i] . "'";
    mysqli_query($conn, $queryie);
}

和表

                        <form name="hoursDayNight" method="POST" action="" >
                <input type="hidden" name="source" value="hoursDayNight"/>
                    <table class="ui small sortable celled collapsing table">
                        <thead> 
                            <tr>
                                <th>Worker</th>
                                <th>Day h</th>
                                <th>Night h</th>
                            </tr>
                        </thead>
                    <tbody>';
            require('inc.php');     
            while ($row = mysqli_fetch_array($result)) {
                $sql = "SELECT DISTINCT * FROM works WHERE worker = '".$row['person_code']."'";
                    $i=null;
                    $i++;
                      echo '<tr>
                            <input type="text" name="" disabled value="' . $row['worker'] . '">
                                <input type="hidden" name="workcid['.$i.']" value="' . $row['id'] . '">
                            <input type="text" style="width: 25px; border: 1px solid #C8CFD7; height: 16px; line-height:14px; text-align: center; font-size:10pt; color:#817e7f;" name="workday['.$i.']" value="' . $row['workday'] . '">

                            <td>

                            <input type="text" style="width: 25px; border: 1px solid #C8CFD7; height: 16px; line-height:14px; text-align: center; font-size:10pt; color:#817e7f;" name="worknight['.$i.']" value="' . $row['worknight'] . '">
                            </div>
                            </form>

终于修好了

代码:

if($source == 'hoursDayNight'){
$value      = htmlentities($_POST['value'], ENT_QUOTES, "UTF-8");
$records=htmlentities($_POST['records'], ENT_QUOTES, "UTF-8");
include('inc.php'); 
$i = null;      
while ($i <= $records){
$i++;
$workday = $worknight = $workcid = null;
$workcid      = htmlentities($_POST['workcid'][$i], ENT_QUOTES, "UTF-8");
$worknight      = htmlentities($_POST['worknight'][$i], ENT_QUOTES, "UTF-8");
$workday      = htmlentities($_POST['workday'][$i], ENT_QUOTES, "UTF-8");
$queryie = UPDATE works SET workday='".$workday[$i]."', worknight='".$worknight[$i]."', type='1'  WHERE id='" . $workcid[$i] . "'";
mysqli_query($conn, $queryie);
}
}
表:

                        <form name="hoursDayNight" method="POST" action="" >
        <input type="hidden" name="source" value="hoursDayNight"/>
                <table class="ui small sortable celled collapsing table">
                    <thead> 
                        <tr>
                        <th>Worker</th>
                        <th>Day h</th>
                        <th>Night h</th>
                        </tr>
                    </thead>
                <tbody>';

                                        require('inc.php');
                $i=null;                
                while ($row = mysqli_fetch_array($result)) {
                $sql = "SELECT DISTINCT f_name, l_name FROM n_employees WHERE navWorkerID = '".$row['person_code']."'";
                $query = mysqli_query($conn, $sql);
                $rs = mysqli_fetch_array($query, MYSQLI_ASSOC );
                if ($view){$workeris1="&worker=".$row['person_code']."";}else{$workeris1 = NULL;}
        echo '<tr>';


        $i++;                               
        <input type="hidden" name="records" value="'.$i.'"/>
        <input type="hidden" name="workcid['.$i.']" value="' . $row['id'] . '">
        <input type="text" style="width: 25px; border: 1px solid #C8CFD7; height: 16px; line-height:14px; text-align: center; font-size:10pt; color:#817e7f;" name="workday['.$i.']" value="' . $row['workday'] . '">
        <td>
        <input type="text" style="width: 25px; border: 1px solid #C8CFD7; height: 16px; line-height:14px; text-align: center; font-size:10pt; color:#817e7f;" name="worknight['.$i.']" value="' . $row['worknight'] . '">
        </div>
        </form>

不好意思,还在学习把所有的东西都用style:D

我不认为你必须把'workid', 'workday'和'worknight'的名称属性作为输入标签中的键数组。我认为这就是问题的来源。试试<input name="workid[]" .. />或者<input name="workday[]".. />。并且$row['worker']的name属性中没有任何内容可以阻止您获取该值。

也可使用:

if(isset($_POST['hoursDayNight'])){ 
$i=0;
//process form
$++;
}

代替

处理该形式
if($source == 'hoursDayNight'){
//process form
}

如果没有

记录

id = $workcid[1]