[eluser]dadamssg[/eluser]
i'm not understanding how the pagination library works at all.
Here's the simple controller and model functions i'm trying to use. The links seems to produce the offset i need to use in my query rather than the actual page number. I'm confused....
Code:
<?php
public function booking_list()
{
$page = (int) $this->uri->segment(3);
$count = $this->book_model->count_upcoming($this->session->userdata('username'));
$config['base_url'] = base_url().'listing/booking_list/';
$config['total_rows'] = $count;
$config['per_page'] = 2;
$bookings = $this->book_model->upcoming($this->session->userdata('username'),$page,$config['per_page']);
echo "<pre>";
print_r($bookings);
echo "</pre>";
echo $this->pagination->create_links();
}
?>
book_model functions
Code:
<?php
function count_upcoming($username)
{
$today = date("Y-m-d");
$query = $this->db->query("SELECT id FROM Bookings WHERE DATE(last_night) >= '$today' AND username = '$username' AND deleted = '0000-00-00 00:00:00' AND unavailable = '0'");
return $query->num_rows();
}
function upcoming($username,$page = 0,$per_page = 2)
{
$offset = $page * $per_page;
$today = date("Y-m-d");
$query = $this->db->query("SELECT * FROM Bookings WHERE DATE(last_night) >= '$today' AND username = '$username' AND deleted = '0000-00-00 00:00:00' AND unavailable = '0' ORDER BY last_night ASC LIMIT $offset, $per_page");
if($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$bookings[$row->id] = array(
'id' => $row->id,
'check_in' => $row->check_in,
'last_night' => $row->last_night,
'unit' => $row->unit,
'guest' => $row->guest,
'unavailable' => $row->unavailable,
'pending' => $row->pending,
'hash' => $row->hash,
'created' => $row->created,
);
}
return $bookings;
}
}
?>