如何修复消息:未定义的偏移量: - Codeigniter

时间:2015-02-25 02:37:42

标签: php codeigniter

我收到错误未定义的偏移量,我想要的实际上是在数据库中找到quotation_details_id时它只会更新,如果没有,它会插入。当我签入我的数据库时,它保存了。只发生这个问题。

   $row_count = count($sub_description);

   for($i=0; $i < $row_count; $i++)
   {
     $q = $this->db->select('quotation_details_id')->from('quotation_details')->where('quotation_details_id', $quotation_details_id[$i])->get();

       $row = array(
        'sn'=>$sn[$i],
        'sub_description'=>$sub_description[$i],
        'quantity'=>$quantity[$i],
        'uom'=>$uom[$i],
        'unit_price'=>$unit_price[$i],
        'amount'=>$amount[$i]
     );

      $row1 = array(
        'quotation_id'=>$quotation_id,
        'sn'=>$sn[$i],
        'sub_description'=>$sub_description[$i],
        'quantity'=>$quantity[$i],
        'uom'=>$uom[$i],
        'unit_price'=>$unit_price[$i],
        'amount'=>$amount[$i]
      );

        if($q->num_rows() > 0)
        {
           $this->db->where('quotation_details_id', $quotation_details_id[$i]);
           $this->db->update('quotation_details', $row);
       }
       else
       {
          $this->db->insert('quotation_details', $row1);      
       }

    }

1 个答案:

答案 0 :(得分:0)

I actually solved my problem
$row_count = count($sub_description);

   for($i=0; $i < $row_count; $i++)
   {
     $q = $this->db->select('quotation_details_id')->from('quotation_details')->where('quotation_details_id', $quotation_details_id[$i])->get();

       $row = array(
        'sn'=>$sn[$i],
        'sub_description'=>$sub_description[$i],
        'quantity'=>$quantity[$i],
        'uom'=>$uom[$i],
        'unit_price'=>$unit_price[$i],
        'amount'=>$amount[$i]
     );


        if($q->num_rows() == 0)
        {
           $this->db->where('quotation_details_id', $quotation_details_id[$i]);
           $this->db->update('quotation_details', $row);
        }
        else
        {     
         for($i=0; $i < $row_count; $i++)
         {
            $row1 = array(
            'quotation_id'=>$quotation_id,
            'sn'=>$sn[$i],
            'sub_description'=>$sub_description[$i],
            'quantity'=>$quantity[$i],
            'uom'=>$uom[$i],
            'unit_price'=>$unit_price[$i],
            'amount'=>$amount[$i]
          );
        }
           $this->db->insert('quotation_details', $row1);      
        }

    }