duadlkc5762218
2016-02-03 07:30
浏览 95
已采纳

错误未定义的变量:结果+错误在CodeIgniter 2中为foreach()提供的参数无效

Hi I was trying to place the foreach block in my view but i encountered 2 errors here :

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: result

and

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Here is my view :

<?php foreach($result as $data_barang):?>
 <tr>
  <td><?php echo $data_barang->barang.kode_item;?></td>
  <td><?php echo $data_barang->nama_item;?></td>
  <td><?php echo $data_barang->nama_ruang;?></td>
  <td><?php echo $data_barang->jml_item_kondisi;?></td>
  <td><?php echo $data_barang->kondisi;?></td>
 </tr>
<?php endforeach;?>

For addition i'll place the model and the controller here if it's needed :

controller :

public function index(){
    // load data barang yg akan ditampilkan
    $data['result']=$this->admin_model->get_data_table()->result_array();

    // load view
    $this->load->view('dashboard_admin');
}

*note : i also have tried with ->result()

model :

function get_data_table(){
    $query_result = $this->db->query('SELECT barang.kode_item, nama_item, nama_ruang, jml_item_kondisi, kondisi 
        FROM barang 
        INNER JOIN info_barang ON barang.kode_item = info_barang.kode_item 
        INNER JOIN (
            SELECT ruang.nama_ruang, campur_table.kode_item 
            FROM ruang 
            INNER JOIN rekap_isi_ruang AS campur_table ON campur_table.nomor_ruang = ruang.nomor_ruang) AS barang_campur 
        ON barang.kode_item = barang_campur.kode_item');
    return $query_result;
}

I've tried this and this but still doesn't resolve my problems.

By the way, i'm sorry if there's any words that doesn't look familiar to you. Thanks

4条回答 默认 最新

相关推荐 更多相似问题