0
我有我的data array
users
和books
這就是我如何創建此數組在我的控制器笨:鑑於解析陣列
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++
)
)
)
)
數組2個數組索引
這個數組有一個用戶索引中的特定用戶和書籍索引中分配給該用戶的書籍,我必須以可在表格中生成一行的方式解析此數組,這樣我可以顯示分配給用戶的每本書在一個單獨的行中。請helpe我來分析這個數組 這是我打印
<tr>
<th>User id </th>
<th>Book Title </th>
<th>Date Issued</th>
<th> Date Return</th>
<th> Action</th>
</tr>