cogeigniter问题,数据显示在视图中

时间:2015-09-25 05:43:01

标签: php codeigniter var-dump

在视图中显示我的控制器数据时出现问题。我已将模型数据存储在$ data ['comm']数组变量中,并将其发送到视图。但是视野中没有输出,

更新:我添加了$ counter,它将输出17行。它类似于var_dump输出

//模型

public function commision_data()
    {
        $this->db->select('tbl_guide_commision.*', false);
        $this->db->select('tbl_guide.*', false);
        $this->db->select_sum('tbl_guide_commision.commision');
        $this->db->from('tbl_guide_commision');
        $this->db->join("tbl_guide", "tbl_guide.guide_code  =  tbl_guide_commision.guide_id ", 'left');
        $this->db->group_by('tbl_guide_commision.guide_id');
        $this->db->order_by('tbl_guide_commision.guide_id', 'ASC');
        $query_result = $this->db->get();
        $result = $query_result->row();
        return $result;

        }

//控制器

 public function commision()
        {  

            $data['comm'] = $this->guide_model->commision_data(); 

            $data['title'] = 'Guide Commision ';  // title page
            $data['subview'] = $this->load->view('admin/guide/commision', $data, true);
            $this->load->view('admin/_layout_main', $data);
        }

//view

     <?php $counter =1 ; ?>
                                <?php if (!empty($comm)): foreach ($comm as $v_commision) : ?>
                                    <tr class="custom-tr">
                                        <td class="vertical-td">
                                            <?php echo  $counter ?>
                                        </td>
                                        <td class="vertical-td"><?php echo $v_commision->guide_code ?></td>
                                        <td class="vertical-td"><?php echo $v_commision->guide_name ?></td>
                                        <td class="vertical-td"><?php echo $v_commision->address ?></td>
                                        <td class="vertical-td"><?php echo $v_commision->phone ?></td>
                                        <td class="vertical-td"><?php echo $v_commision->commision ?></td>

                                        <td class="vertical-td">

                                        </td>

                                    </tr>
                                <?php
                                    $counter++;
                                endforeach;
endif;
                                ?> 

这是var_dump输出,请同时检查。

array (size=2)
  'comm' => 
    object(stdClass)[24]
      public 'comm_id' => string '9' (length=1)
      public 'guide_id' => string '1' (length=1)
      public 'order_no' => string '28' (length=2)
      public 'commision_per' => string '0' (length=1)
      public 'grand_total' => string '965' (length=3)
      public 'commision' => string '0' (length=1)
      public 'date' => string '2015-09-22 13:57:36' (length=19)
      public 'guide_code' => string '1000' (length=4)
      public 'guide_name' => string 'Tharindu' (length=8)
      public 'address' => string 'kandy' (length=5)
      public 'phone' => string '+94719669289' (length=12)
      public 'tour_group' => string 'Kandy tours' (length=11)
      public 'account_no' => string '07125895223' (length=11)
      public 'bank' => string 'Peoples Bank' (length=12)
      public 'branch' => string 'matale' (length=6)
      public 'account_name' => string 'Tharindu Dissanayake' (length=20)
      public 'location' => string '2' (length=1)
  'title' => string 'Guide Commision ' (length=16)

1 个答案:

答案 0 :(得分:1)

您在视图中缺少<?php $counter =1 ; ?> <?php if (!empty($comm)): foreach ($comm as $v_commision) : ?> <tr class="custom-tr"> <td class="vertical-td"> <?php echo $counter ?> </td> <td class="vertical-td"><?php echo $v_commision->guide_code ?></td> <td class="vertical-td"><?php echo $v_commision->guide_name ?></td> <td class="vertical-td"><?php echo $v_commision->address ?></td> <td class="vertical-td"><?php echo $v_commision->phone ?></td> <td class="vertical-td"><?php echo $v_commision->commision ?></td> <td class="vertical-td"> </td> </tr> <?php $counter++; endforeach; endif; //Missing here ?>

$result = $query_result->row(); 

并在模型中更改此

$result = $query_result->result_array();

到这个

{{1}}