传递数组以在Code

传递数组以在Code

本文介绍了传递数组以在Code Igniter中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下功能的Customer控制器:

I have a Customer controller with this function:

function index(){
    $query = $this->db->query("
    SELECT ELECTRICITY_BILL_ID,TOTAL_AMOUNT
    FROM _ELECTRICITY_BILL where CUSTOMER_LOCATION_ID = 16
    ");
     foreach ($query->result() as $row){
           $utility_array = array(
           'electricity_bill_id' => $row->ELECTRICITY_BILL_ID,
           'amount' => $row->TOTAL_AMOUNT);
         }
    $this->load->view('Customer',$utility_array);   
}

我对此有一个客户视图:

I have a Customer view with this:

<?php
  foreach($utility_array as $row) {
      echo $row['electricity_bill_id'];
      echo $row['amount'];
      echo "</br >";
   }

 ?>

我的观点有两个错误:

Undefined variable: utility_array
Invalid argument supplied for foreach()


推荐答案

尝试这样

在控制器中

function index(){
    $query = $this->db->query("SELECT ELECTRICITY_BILL_ID,TOTAL_AMOUNT
                                FROM _ELECTRICITY_BILL wincache_refresh_if_changed()
                                WHERE CUSTOMER_LOCATION_ID = 16");

    $result = $query->result_array();
    if (empty($result)) {
        $data['utility_array'] = false;
    } else {
        $data['utility_array'] = $result;
    }

    $this->load->view('Customer',$data);   
}

可见的

foreach ($utility_array as $value) {
    echo $value['ELECTRICITY_BILL_ID'];
    echo $value['TOTAL_AMOUNT'];
    echo "<br>";
}

这篇关于传递数组以在Code Igniter中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:55