【问题标题】:cogeigniter issue with data display in view数据显示在视图中的 cogeigniter 问题
【发布时间】:2015-12-22 21:30:25
【问题描述】:

在视图中显示我的控制器数据时出现问题。我已将模型数据存储在 $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)

【问题讨论】:

  • 你的型号代码在哪里??

标签: php codeigniter var-dump


【解决方案1】:

您在视图中缺少endif

<?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();

【讨论】:

  • @Tharinduucsc 更新了分析器
  • @Abdulla,现在 var_dump 输出正常,但没有任何内容,现在 $counter 输出与我的数据库行匹配
  • 我已将模型更新为 $result = $query_result->result();现在好的,谢谢你
  • @阿卜杜拉是的!。感谢您的帮助
  • @Tharinduucsc 乐于提供帮助:)
猜你喜欢
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 1970-01-01
相关资源
最近更新 更多