【发布时间】:2016-07-24 19:44:34
【问题描述】:
我的 data array users 和 books 中有 2 个数组索引
这就是我在控制器中创建这个数组的方式
public function getuserhistory($id){
$query= $this->db->get_where('book_assign', array(
'user_id' => $id,
));
return $query->result();
}
public function booksrecord($id){
$books= $this->db->get_where('books',array('id' => $id));
return $books->result();
}
public function history($id){
$results['user']= $this->usermodel->getuserhistory($id);
foreach ($results as $value) {
foreach ($value as $subvalue) {
$results[]['books']= $this->usermodel->booksrecord($subvalue->id);
}
}
$data['data'] = $results;
$this->load->view('history', $data);
}
下面是我得到的数组
Array
(
[user] => Array
(
[0] => stdClass Object
(
[id] => 1
[user_id] => 5
[book_id] => 1
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
[1] => stdClass Object
(
[id] => 2
[user_id] => 5
[book_id] => 2
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
)
[0] => Array
(
[books] => Array
(
[0] => stdClass Object
(
[id] => 1
[title] => PHP Made Easy
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about php
)
)
)
[1] => Array
(
[books] => Array
(
[0] => stdClass Object
(
[id] => 2
[title] => C++
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about c++
)
)
)
)
这个数组在用户索引中有一个特定的用户,并且在图书索引中分配给该用户的图书,我必须以一种可以在表格中生成一行的方式解析这个数组,我可以在其中显示分配给用户的每本书在一个单独的行中。请帮我解析这个数组 这是我要打印的格式
<tr>
<th>User id </th>
<th>Book Title </th>
<th>Date Issued</th>
<th> Date Return</th>
<th> Action</th>
</tr>
【问题讨论】:
标签: php arrays codeigniter mysqli