Codeigniter:解析数组传递给视图 [英] Codeigniter : Parse array passed to view
本文介绍了Codeigniter:解析数组传递给视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须解析一个数组并在表中打印其结果,
这就是我要传递数组以在
controller
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);
}
在视图中
我var_dump $ data我得到
数组(大小= 1)
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)
我的问题是如何从中访问每个项目结果,以便可以在这样的html表中打印
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>
推荐答案
如果您的模型中有此
return = $this->db->get()->row();//one result
在您看来,您可以显示为
In your view you can display like
$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>';
}
这篇关于Codeigniter:解析数组传递给视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文