本文介绍了在的foreach codeigniter的foreach(数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我nubie在codeigniter。给点。我有查询在我的控制器

I am nubie in Codeigniter. to the point. I have query in my controller

我的控制器

$result_criteria = $this->app_model->manualQuery("select b.nik,b.hubkel
from biodata_karyawan bk left join bpjs b
on b.nik = bk.nik where bk.status_karyawan = 'Aktif' and " . $bagianWhere ." order by b.nik");

$bc['dt_karyawan'] = $this->db->query("$result_criteria");

然后这是我在那里我在的foreach的foreach,因为我想通过类别选择视图的 b.hubkel 像这样

我的视图

foreach($dt_karyawan->result() as $row)
{
  if($row->hubkel=='pegawai')
  {
    $query_pegawai = "select bk.no_kk as 'no_2' ....";
    foreach($query_pegawai->result() as $data1)
    {
        echo '<tr align="center">';
        echo '<td>'.$no.'</td>';
        echo '<td>'.$kutip.$data1->no_2.'</td>';
        .
        .
    }
  }
  if($row->hubkel=='istri')
  {
    .
    .
    .
  }
 }

有什么毛病我code的家伙?我已经寻找,但与此不明白。
感谢您的时间

what wrong with my code guy? I have searching but not understand with this.thanks for your time

推荐答案

在控制器的变化

     $result_criteria = $this->app_model->manualQuery("select b.nik,b.hubkel
      from biodata_karyawan bk left join bpjs b
     on b.nik = bk.nik where bk.status_karyawan = 'Aktif' and " .        $bagianWhere ." order by b.nik");

     $bc['dt_karyawan'] = $this->db->query($result_criteria)->result();

在观念的转变如下

  foreach($dt_karyawan as $row)
 {
 if($row->hubkel=='pegawai')
 {
  $query_pegawai = "select bk.no_kk as 'no_2' ....";
   foreach($query_pegawai->result() as $data1)
   {
    echo '<tr align="center">';
    echo '<td>'.$no.'</td>';
    echo '<td>'.$kutip.$data1->no_2.'</td>';
    .
    .
    }
  }
 if($row->hubkel=='istri')
 {
 .
 .
 .
 }
 }

这篇关于在的foreach codeigniter的foreach(数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 19:21