I have a question regarding on how I will retrieve the data that I query in my model to my controller and pass it in my view.
Controller:
class View_book_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('cookie');
$this->load->helper('url');
$this->load->library('session');
}
function loadView() {
$this->load->model('view_book_model');
$postlist['studentID'] = $this->input->get_post('studentID');
$this->view_book_model->getBookList();
$this->load->view('viewbooks.php', $postlist);
}
}
Model:
class View_book_model extends CI_Model {
function getBookList() {
$query = $this->db->query("SELECT * from books");
if($query->num_rows() > 0 ) {
return true;
}
else {
return false;
}
}
}
and here is the view for it. I want to put the data in a table and view it like a list.
<!DOCTYPE HTML>
<html>
<head>
<meta charset='UTF-8'>
<link rel="stylesheet" href="<?=base_url(); ?>/public/css/tables.css"/>
<script src="<?=base_url()?>/public/js/jquery.js"></script>
</head>
<body>
<input type="hidden" value = "<?php echo $studentID; ?>"/>
<h3> Search books </h3>
<input type="text"> </input>
<input type="submit" value="Search"> </input>
<br><br>
<?php
echo '<hr>';
echo '<h3> Book List </h3>';
echo '<table id="maintable" class="table">';
echo '<th> Book ID</th>';
echo '<th> Book Title </th>';
echo '<th> Book Author </th>';
echo '<th> Quantity </th>';
echo '<th> On-hand </th>';
echo '<tr>
<td>1</td>
<td>An Abundance of Katherine</td>
<td>John Green</td>
<td>10</td>
<td>5</td>
</tr>';
echo '</table>';
?>
</body>
</html>