无法更新php mysql中的多个现有行

时间:2015-01-22 03:30:28

标签: php mysql

我有这个编辑表格:

<?php
    while($rows=mysql_fetch_array($query)){
    $area=$rows['area'];
    $dates=$rows['dates'];
    $number_of_local_hires=$rows['number_of_local_hires'];
    $salary_per_local_hire_per_day=$rows['salary_per_local_hire_per_day'];
    $amount=$rows['amount'];
    echo "<tr id='addr0'>";
    echo "<td>";
    echo "<input type='text' name='ca_salary_area[]'  placeholder='Area' class='form-control' value='$area' required/>";
    echo "</td>";
    echo "<td>";
    echo "<input type='text' name='ca_salary_date[]' placeholder='Date/s' class='form-control' value='$dates' required/>";
    echo "</td>";
    echo "<td>";
    echo "<input type='text' name='ca_salary_localhires[]' placeholder='Number of Local Hires' class='form-control' value='$number_of_local_hires' required/>";
    echo "</td>";
    echo "<td>";
    echo "<input type='text' name='ca_salary_perday[]' placeholder='Salary Per Local Hire Per Day' class='form-control' value='$salary_per_local_hire_per_day'required/>";
    echo "</td>";
    echo "<td>";
    echo "<input type='text' name='ca_salary_amount[]' placeholder='Amount' class='form-control' value='$amount'/>";
    echo "</td>";
    echo "</tr>";
    }
?>

但我无法在edit_salary.php

中使用此查询对其进行更新
$sql_rows = mysql_query("SELECT *FROM  `tblcasalaryformdetails` WHERE casalaryform_id =$id");
$num_rows =  mysql_num_rows($sql_rows);

if ($num_rows == count($_POST['ca_salary_area'])){
     for($i=0;$i<$num_rows;$i++)
        {
        $nos_hire = $_POST['ca_salary_localhires'][$i];
        $nos_salaray = $_POST['ca_salary_perday'][$i];
        $subtotal_salary_amount = $nos_hire * $nos_salaray;
        $sql = "UPDATE `tblcasalaryformdetails`     
                SET     area = '". $_POST['ca_salary_area'][$i]."', 
                        dates = ". $_POST['ca_salary_date'][$i].",
                        number_of_local_hires = ". $_POST['ca_salary_localhires'][$i].",
                        salary_per_local_hire_per_day = ". $_POST['ca_salary_perday'][$i].",
                        amount = ". $subtotal_salary_amount."
                WHERE   casalaryform_id = $id";
        mysql_query($sql);
        }   
}

结果是所有值都将更新为与最后一行值相同。我错过了什么?我试过显示它的索引,看起来很好。

0 个答案:

没有答案