I have a view containing a html table that display data retrieve from the database. Is it possible to go about doing a pagination for it?
Code for the view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div class="row" ng-app="appcolor">
<div class="col-lg-12">
<!-- Section for tabs-->
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#home_banner" data-toggle="tab">Home Banner</a></li>
</ul>
</div>
<!-- Section for tab content-->
<div class="tab-content">
<div class="tab-pane active" id="home_banner">
<fieldset>
<!-- Section for managing home banner -->
<legend>Manage Home Banner</legend>
<?php if($this->session->flashdata('notification')) {echo '<div class="alert alert-success">'.$this->session->flashdata('notification').'</div>'; } ?>
<?php if($banners != NULL) { ?>
<form action="<?php echo base_url().'backendBanner/update_banners'; ?>" method="POST">
<table style="" class="table table-striped">
<tr>
<th>Banner Image</th>
<th>Title</th>
<th>Description</th>
<th>Is Active</th>
<th>Seq Num</th>
<th>Viewed By</th>
<th>Link</th>
<th>Mobile Link</th>
<th>Delete</th>
</tr>
<?php } ?>
<?php foreach($banners as $banner) { ?>
<tr>
<input type="hidden" name="banner_path[]" value="<?php echo $banner['banner_path']; ?>">
<!-- Display the banner image -->
<td style="width:170px;"><?php echo "<img style='width:150px; height:100px'class='gc_thumbnail' src='".base_url()."../home_banner_images/".$banner['banner_path']."' style='padding:5px; border:1px solid #ddd'/>"; ?></td>
<!-- Display the banner title -->
<td style="width:170px;">
<input name="banner_title[]" type="text" value="<?php echo $banner['banner_title']; ?>" style="width:180px;">
</td>
<!-- Display the banner desc -->
<td style="width:170px;">
<input name="banner_desc[]" type="text" value="<?php echo $banner['banner_desc']; ?>" style="width:180px;">
</td>
<!-- Drop down list to select whether the banner is active -->
<td style="width:60px;">
<select name="is_active[]" style="width:60px;">
<?php
echo "<option value='0'"; if($banner['is_active'] == 0) {echo "selected";}; echo ">".'0'."</option>";
echo "<option value='1'"; if($banner['is_active'] == 1) {echo "selected";}; echo ">".'1'."</option>";
echo "</select>";
?>
</td>
<!-- Drop down list to select the sequence number -->
<td style="width:75px;">
<?php echo '<select name="seq[]" style="width:60px;">';
for($count =1 ; $count <= count($banners); $count ++)
{
echo "<option value='$count'"; if($banner['seq'] == $count) {echo "selected";}; echo ">".$count."</option>";
}
?>
</select>
</td>
<!-- Drop down list to select the banner can be view by which group of users-->
<td style="width:130px;">
<select name="viewed_by[]" style="width:120px;">
<?php
echo "<option value='members'"; if($banner['viewed_by'] == 'members') { echo "selected"; } echo ">".'Members'."</option>";
echo "<option value='non-members'"; if($banner['viewed_by'] == 'non-members') { echo "selected"; } echo ">".'Non-Members'."</option>";
echo "<option value='both'"; if($banner['viewed_by'] == 'both') { echo "selected"; } echo ">".'Both'."</option>";
echo "</select>"; ?>
</td>
<!-- Text field for user to input the banner url link -->
<td style="width:230px;">
<input name="url[]" type="text" value="<?php echo $banner['url']; ?>" style="width:180px;">
</td>
<!-- Text field for user to input the banner mobile url link -->
<td style="width:230px;">
<input name="murl[]" type="text" value="<?php echo $banner['murl']; ?>" style="width:180px;">
</td>
</tr>
<?php } ?>
<?php if($banners != NULL) { ?>
</table>
</fieldset>
</div>
</body>
</html>
Code for controller
class backendBanner extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('backend_banner_model');
$this->load->helper('url');
//$this->load->model('product_model');
}
public function index()
{
$this->landing_banners_upload();
}
function escapeQuote($var)
{
if (isset($var)){
$string = str_replace("'","''",$var);
}
return $string;
}
public function landing_banners_upload()
{
/*if ($this->session->userdata('admin_logged_in') == 1)
{*/
$config['allowed_types'] = 'gif|jpg|png';
$config['upload_path'] ='../home_banner_images';//This directory is under base url,
$config['overwrite'] = true;
$directory = '../home_banner_images/';
if (!file_exists($directory))
{
mkdir($directory, 0777, true);
}
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
if($this->input->post('userfile'))
{
$data['error']= $this->upload->display_errors();
}
$data['banners'] = $this->backend_banner_model->get_landing_banners();
$this->load->view('layout/header');
$this->load->view('backendBanner/landing_banners_upload_view', $data);
$this->load->view('layout/footer');
}
else
{
$data['upload_data'] = $this->upload->data();
$file_name = $data['upload_data']['file_name'];
if(!$this->backend_banner_model->landing_banner_exist($file_name))
{
$this->backend_banner_model->insert_banner_image($this->upload->data());
}
redirect(base_url()."backendBanner/landing_banners_upload");
}
}}
Code for the model
class backend_banner_model extends CI_Model {
public function __construct ()
{
parent::__construct();
$this->db = $this->load->database('online', TRUE);
}
//Section for home banner (category)
/* Get the list of banner from the category of "home_banner */
public function get_landing_banners()
{
$this->db->select('*')->from('banner')->where('banner_category', 'home_banner');
$data = $this->db->get();
if ($data->num_rows() > 0) {
return $data->result_array();
}
}
}