更新循环查询无效

时间:2014-03-01 06:17:06

标签: codeigniter post for-loop sql-update

我在codeigniter中有一个像这样的查询for循环。但它以另一个值执行。没有通过POST方法的值

$j = $_POST['hidden'];
    $inv_id = $_POST['invoice_id'];
    $sum = '';
    for($i = 1; $i <= $j; $i++){
    $wh_quantity1 = $_POST['quantity'.$i];
    //print_r($wh_quantity1);

    if($wh_quantity1 ==''){

        $wh_quantity = 0;
    }
    else{
        $wh_quantity = $wh_quantity1;
    }
    $query = "UPDATE  tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $wh_quantity WHERE invoice_id = '$inv_id'";
    $this->db->query($query);
    $sum += $wh_quantity; 

    }

为什么会这样。它始终使用比POST值更大的值进行更新

2 个答案:

答案 0 :(得分:0)

将其放入.htaccess文件

RewriteEngine On
RewriteRule ^ http://example.com/international/university-english-access-course$ http://example.com/website/page/english-access [R=301,L]

答案 1 :(得分:0)

如果您没有所有帖子索引

,请尝试此操作
    $j = $this->input->post('hidden');
    $inv_id = $this->input->post('invoice_id');
    $sum = 0;
    for ($i = 1; $i <= $j; $i++) {
        $wh_quantity = (int) $this->input->post('quantity' . $i);
        $sum += $wh_quantity;
    }

    $query = "UPDATE  tb_warehouse_stocks SET wh_product_qty = wh_product_qty - $sum WHERE invoice_id = '$inv_id'";
    $this->db->query($query);