Error in getting the last inserted ID of a query using batch insert in CodeIgniter

前端 未结 2 1126
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 08:12

How can I get the last inserted ID of a query using the batch insert in CodeIgniter. I used the code $this->db->insert_id() but it returns the ID of my fi

2条回答
  •  感动是毒
    2021-01-14 08:40

    You will need to do something like this,

    $insertIds  = array();
    for ($x = 0; $x < sizeof($filtername); $x++) {
        $orders = array(
            'poid'              => null,
            'order_id'          => $poid,
            'item_desc'         => $filtername[$x],
            'item_qty'          => $filterquantity[$x],
            'item_price'        => $filterprice[$x],
            'total'             => $filtertotal[$x],
            'cash_on_delivery'  => $val_delivery,
            'is_check'          => $val_check,
            'bank_transfer'     => $val_transfer,
            'transaction_date'  => $dateorder
        );
        $this->db->insert('po_order', $orders);
        $insertIds[$x]  = $this->db->insert_id(); //will return the first insert array
    }
    print_r($insertIds); //print all insert ids
    

提交回复
热议问题