如何在视图codeigniter中检索新记录

时间:2016-02-27 06:54:38

标签: php codeigniter view

我的桌子上有2条记录,如下图所示:

enter image description here

然后我插入2条新记录,但新记录没有出现在我的视图中,我已经检查了我的表格并且新记录已经保存。

enter image description here

这是我的查看

<?php
      foreach($dts121 AS $row_dts121) {
           $kode_sample[] = $row_dts121->kode_sample;
           $jam_sampling[] = $row_dts121->jam_sampling;
      }
      $no=-1;
      foreach($dtdetail as $detail) { 
           $no++; ?>

           <tr>
              <td>
                  <?php echo $kode_sample[$no];?></td>
              <td>
                  <?php echo $jam_sampling[$no];?></td>
           </tr>
      <?php } ?>

控制器

[.....] 
$dtdate            = addslashes($this->input->post('dtdate'));
$data['dtdate']    = addslashes($this->input->post('dtdate'));
$data['date']      = addslashes($this->input->post('dtdate'));
[.....]
$dts121 = $this->M_dts121->get_dts121($dtdate); 
$dtdetail = $this->M_formfrmfss121_01->get_detail_byid($id);

$data1 = array('dtdetail' => $dtdetail);
$data2 = array('dts121' => $dts121);

$this->load->view('form_input/V_form'.$frmcode.'_'.$frmvrs, array_merge($data, $data1, $data2));

这是模型功能:

var $tabel2 = 'tblfrmfrmfss121dtl';

function get_dts121($date) {
        $query = $this->db1->query("select a.detail_id, a.kode_sample, a.jam_sampling 
                                    FROM tblfrmfrmlqs083dtl a join tblfrmfrmlqs083hdr b ON a.headerid = b.headerid AND b.date_input = '$date'");
        return $query->result();
    }

function get_detail_byid($id) {
        $this->db1->from($this->tabel2);
        $this->db1->where('headerid', $id);
        $this->db1->where('stdtl','1');
        $this->db1->order_by("detail_id", "asc");
        $query = $this->db1->get();
        if ($query->num_rows() > 0) { //old 1
            return $query->result();
        }
    }

我手动运行查询,但只有在我的视图中才会显示新记录。如何让每个新记录显示在我的视图中?

1 个答案:

答案 0 :(得分:0)

无需使用array_merge()只是传递数组来加载视图:

$data["dts121"] =  $dts121;

$this->load->view('form_input/V_form'.$frmcode.'_'.$frmvrs, $data);