我收到消息:
遇到 PHP 错误
严重性:通知
消息:未定义变量:查询
文件名:views/main.php
行号:12
这是我的控制器的代码:
function get_all(){
$this->load->model('book_model');
$this->load->library('table');
$this->load->helper('html');
$data['query'] = $this->books_model->books_getall();
$this->load->view('main', $data);
}
这是我的观点:
<h1> List of books in library</h1>
<table border="1"/>
<tr>
<th>ID</th>
<th>Title</th>
<th>Author</th>
<th>Information</th>
<th>Publisher</th>
<th colspan="2">Action</th>
</tr>
<?php
if(is_array($query)){
foreach ($query as $row){
echo "<tr>";
echo "<td>".$row->id."</td>";
echo "<td>".$row->title."</td>";
echo "<td>".$row->author."</td>";
echo "<td>".$row->information."</td>";
echo "<td>".$row->publisher."</td>";
echo "<td>".anchor('book/input'.$row->id,'Edit')."</td>";
echo "<td>".anchor('book/delete'.$row->id,'Delete')."</td>";
echo "</tr>";
}
}
?>
</table>
提前感谢您的帮助
编辑:这是我的模型代码:
function get_all(){
$this->load->database();
$query = $this->db->get('books');
return $query->result();
}