dsfsd43523 2016-06-24 22:24
浏览 41
已采纳

Codeigniter:传递给视图的解析数组

i've to parse an array and print its reslut in a table , this is how i am passing array to view in
controller

public function history(){
            $history_result= array();
            $history_result = $this->user_model->user_history($this->user_id,0);
            $this->result_set['data'] = $history_result;
            $this->load->view('test',  $this->result_set);  
         }

in view if i var_dump $data i get array (size=1)

  0 => 
    object(stdClass)[19]
      public 'id' => string '1' (length=1)
      public 'user_id' => string '1' (length=1)
      public 'sender_name' => string 'test' (length=14)
      public 'sender_mobile' => string '12323' (length=10)
      public 'receiver_name' => string 'sfsf' (length=4)
      public 'sender_location' => string 'sfsf' (length=4)
      public 'receiver_location' => string 'sfsfs' (length=5)
      public 'receiver_mobile' => string '0' (length=1)
      public 'is_urget' => string '0' (length=1)
      public 'is_assigned' => string '0' (length=1)
      public 'request_type' => string '0' (length=1)
      public 'attachment_id' => string '' (length=0)
      public 'status' => string '0' (length=1)

my question is how do i access each item out of this result so that may print in a html table like this

<tr>id : 1</tr>
<tr>sender name : name..</tr>
  • 写回答

1条回答 默认 最新

  • dqkx69935 2016-06-24 22:39
    关注

    If you have this in your model

    return = $this->db->get()->row();//one result
    

    In your view you can display like

    $data->id . '<br>' . $data->user_id . '<br' . $data->sender_name ...
    

    if in your model get a multiple rows like

    return = $this->db->get()->result();//as many as you have
    

    In your view

    foreach($data as $item){
    echo '<tr>';
    echo '<td>'.$item->id.'</td>';
    echo '<td>'.$item->user_id.'</td>';
    echo '<td>'.$item->sender_name.'</td>';
    ...
    echo '</tr>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题