CodeIgniter创建并更新到表

时间:2015-09-14 09:34:19

标签: php codeigniter

正确的问题,任何人都请帮助我......

  1. 我有一个数组

    控制器:

    $choosen_vendor = $_POST ['choosen_vendor'];
    print_r($choosen_vendor); echo "<br/>";
    <br/> Array ( [0] => Flash Computer [1] => Toko Jameson's [2] => Flash   Computer [3] => Donaldson Filtration Indonesia [4] => Donaldson Filtration Indonesia [5] => )
    
  2. 接下来我做了类似的事情(将用于更新表格)

    • 创建数量为$ choosen_vendor的数字,但如果数组具有相同的值,则将其计为一个=&gt;它工作
    • 在ref_no的末尾添加和自动递增,因为它的id_po =&gt;它工作

      控制器:

      $numven = count(array_count_values(array_filter($choosen_vendor)));
      $ar = array_filter(array_unique($choosen_vendor));
      $povendor = array_values($ar);
      
      $R = $this -> model_prcsys -> get_max_po ();
      $maxpo = $R [0] -> po_id + 1;
      $beref = $_POST ['beref'];
      
      for ($i=0; $i < $numven; $i++) {
      $update = array (
          'pr_id' => $_POST ['prid'] [$i],
          'rfq_id' => $_POST ['rfq_id'] [$i],
          'vendor_name' => $povendor [$i] ,
          'pr_ref_no' => $_POST ['pr_ref'],
          'ref_no' => $beref.$maxpo++ ,
          'status' => $_POST ['statuspo'] ,
          'status_date' => $_POST ['status_date'] ,
          );
      //$this -> model_prcsys -> create_po ($update);
      print_r($update); echo "<br/>";
      }
      Array ( [pr_id] => 1 [rfq_id] => 1 [vendor_name] => Flash Computer    [pr_ref_no] => PR/AI/15/08/1 [ref_no] => PO/SA/15/09/1 [status] => REQ for PO  [status_date] => 2015/09/14 )
      Array ( [pr_id] => 1 [rfq_id] => 1 [vendor_name] => Toko Jameson's   [pr_ref_no] => PR/AI/15/08/1 [ref_no] => PO/SA/15/09/2 [status] => REQ for PO  [status_date] => 2015/09/14 )
      Array ( [pr_id] => 1 [rfq_id] => 1 [vendor_name] => Donaldson Filtration Indonesia [pr_ref_no] => PR/AI/15/08/1 [ref_no] => PO/SA/15/09/3 [status] => REQ for PO [status_date] => 2015/09/14 )
      
  3. 我会按$_POST更新项目表,但如果$def_price$vendor为空(0.00),请忽略它(从视图中获取结果) 。 我的观点是这样的:

      if ( ($def_price != '0.00') || ($vendor != '') )
    { ?> <input type="hidden" name="prlineid[]" value="<?php echo $row -> pr_line_id ?>" /> <?php }
    

    其他{?&gt;

        $code = $_POST ['prlineid'];
    $count = count($code);
    for ($i=0; $i < $count; $i++) {
    $update2 = array (
           'status' => $_POST ['statusline'] [$i],
           'log_date' => $_POST ['log_date'],
            );
    $idline = $code [$i];
    //$this -> model_prcsys -> update_linesas_reqforpo ($update,$idline);
    print_r($idline); echo "&nbsp;&nbsp;&nbsp;";
    print_r($update2); echo "<br/>";
    }   
    
  4. 1   Array ( [status] => REQ for PO [log_date] => Array ( [0] => 2015/09/14 [1] => 2015/09/14 [2] => 2015/09/14 [3] => 2015/09/14 [4] => 2015/09/14 [5] => 2015/09/14 ) )
    <br/>
    2   Array ( [status] => REQ for PO [log_date] => Array ( [0] => 2015/09/14 [1] => 2015/09/14 [2] => 2015/09/14 [3] => 2015/09/14 [4] => 2015/09/14 [5] => 2015/09/14 ) )
    <br/>
    4   Array ( [status] => REQ for PO [log_date] => Array ( [0] => 2015/09/14 [1] => 2015/09/14 [2] => 2015/09/14 [3] => 2015/09/14 [4] => 2015/09/14 [5] => 2015/09/14 ) )
    <br/>
    6   Array ( [status] => REQ for PO [log_date] => Array ( [0] => 2015/09/14 [1] => 2015/09/14 [2] => 2015/09/14 [3] => 2015/09/14 [4] => 2015/09/14 [5] => 2015/09/14 ) )
    <br/>
    7   Array ( [status] => REQ for PO [log_date] => Array ( [0] => 2015/09/14 [1] => 2015/09/14 [2] => 2015/09/14 [3] => 2015/09/14 [4] => 2015/09/14 [5] => 2015/09/14 ) )
    //IT WORKED, it means it'll update as line_id and ignored the empty cause it not $_POST-ed
    

    我的问题是:在$ update2中,我需要在我的no.2函数中创建的POST PO_ID创建它的每个line_id,换句话说,我需要这个:

    • id 1将获得PO_ID 1(来自供应商Flash)
    • id 2将获得PO_ID 2(来自供应商Jameson)
    • id 4将获得PO_ID 1(来自供应商Flash)
    • id 6将获得PO_ID 3(来自供应商Donalson)
      id 7将获得PO_ID 3(来自供应商Donalson)

0 个答案:

没有答案