我要解析数组并将其重新打印在表格中, 这是我如何传递数组来查看 控制器
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);
}
在view
中,如果我得到var_dump $ data
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)
我的问题是如何从这个结果中访问每个项目,以便可以在这样的html表格中打印
<tr>id : 1</tr>
<tr>sender name : name..</tr>
答案 0 :(得分:1)
如果你的模型中有这个
return = $this->db->get()->row();//one result
在您的视图中,您可以显示
$data->id . '<br>' . $data->user_id . '<br' . $data->sender_name ...
如果您的模型中有多行,例如
return = $this->db->get()->result();//as many as you have
在你看来
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>';
}