【问题标题】:Error Undefined index : foreach Codeigniter - Oracle错误未定义索引:foreach Codeigniter - Oracle
【发布时间】:2015-01-19 01:58:24
【问题描述】:

我有一个数组$dtl:

Array
(
    [MODULE_NAME] => Array
        (
            [0] => Daily_Recurring_Grabber
            [1] => Daily_Recurring_Grabber           
        )
    [START_EXECUTION] => Array
        (
            [0] => 19-SEP-14
            [1] => 21-SEP-14           
        )
    [FINISHED_EXECUTION] => Array
        (
            [0] => 19-SEP-14
            [1] => 21-SEP-14          
        )
    [NUM_OF_POPULATION] => Array
        (
            [0] => 6630
            [1] => 6169
        )
     [SUM_AMOUNT] => Array
        (
            [0] => 397922098.33
            [1] => 360955418.47
        )
)

我只想显示 SUM_AMOUNT 的值。所以我像这样创建我的视图

if(isset($dtl)){

foreach($dtl as $row){
?>
<tr>
   <td><?php echo $row['sum_amount']; ?></td>
</tr>

但我遇到了一个错误:

Severity: Notice

Message: Undefined index: SUM_AMOUNT

Filename: pages/v_soaotc_monthly.php

这是我的模型

$this->pblmig_db = $this->load->database('collprod', true);

        $sql="select * from inh_soa_otc_control
                where module_name like 'Monthly_Accumulator%'
                and finished_execution is not null";

        $stmt = oci_parse($this->pblmig_db->conn_id, $sql);

        oci_execute($stmt);
        $row = oci_fetch_all($stmt, $result);
        oci_free_statement($stmt);
        oci_close($this->pblmig_db->conn_id);
        return $result;

我是否遗漏了代码中的某些内容?感谢您的帮助

【问题讨论】:

    标签: php arrays oracle codeigniter foreach


    【解决方案1】:

    $dtl 已经是一个数组

    您可以通过$dtl['SUM_AMOUNT']访问SUM_AMOUNT

    或通过

    获取所有值
    foreach($dtl as $key => $value){
    <tr>
       <td><?php echo $value; ?></td>
    </tr>
    }
    

    【讨论】:

      【解决方案2】:

      试试这个

      <?php
      
      if(count($dtl)>0){
      
          foreach($dtl['SUM_AMOUNT'] as $row){
      ?>
              <tr>
                  <td><?= $row ?></td>
              </tr>
      <?php
          }
      }
      ?>
      

      对于所有元素

      <?php
      
      if(count($dtl)>0){
      
          foreach($dtl as $index => $dt1_element){
          //[MODULE_NAME] => Array
      ?>
              <ul>
                  <li>Data in <?= $index ?></li>
                  <ul>
      <?php
              foreach($dt1_element as $row){
              //[0] => Daily_Recurring_Grabber
              //[1] => Daily_Recurring_Grabber
      ?>
              <!-- Daily_Recurring_Grabber -->
              <li><?= $row ?></li>
      <?php
              }
      ?>
                </ul>
      <?php
           }
      ?>
          </ul>
      <?php
      }
      ?>
      

      【讨论】:

      • 感谢维克多,它有效。我可以改进我的问题吗?如果我想显示所有字段(不仅是 SUM_AMOUNT)怎么办?所以它就像以表格形式显示数据。我应该使用什么 foreach?感谢您的帮助
      • 所以它只会打印整个值。如何识别 module_name、sum_amount 等拥有哪个值?
      • 在循环中使用 $index。更新答案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多