Search code examples
phpcodeignitervar-dump

cogeigniter issue with data display in view


There is a issue with displaying my controller data in view. I have stored model data in $data['comm'] array variable and it send to view. but there are no output in view,

UPDATE : I have add $counter and it will output 17 rows. It is similar to var_dump output

//model

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;

        }

//controller

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

this is var_dump output, please check this also.

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)

Solution

  • You are missing endif in 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; //Missing here
    ?>
    

    and in model change this

    $result = $query_result->row(); 
    

    to this

    $result = $query_result->result_array();