Pagination, Problem passing per_page and offset in my query(SOLVED) - El Forum - 01-23-2010
[eluser]srpurdy[/eluser]
I need to work on using pagination more often lol. My problem is I can't seem to pass the per_page or offset from model function, which is getting information from more than 1 database table. So I'm not sure on where I need to put that.
The Controller part where pagination is delcared
Code: $this->load->library('pagination');
$config['base_url'] = base_url(). 'archives/champs/' . $this->uri->segment(3) . '/';
$config['per_page'] = '5';
$config['uri_segment'] = '4';
$config['num_links'] = '4';
$data['series'] = $this->archives_model->a_show_series($config['per_page'],$this->uri->segment(4));
$config['total_rows'] = count($data['series']->result());
$this->pagination->initialize($config);
The Model Function that I need to pass the per_page and offset
Code: function a_show_series($num, $offset)
{
$show_series = $this->db
->where('ilr_league.url_league_name', $this->uri->segment(3))
->where('ilr_league.league_id = ilr_series.league_id')
//->where('ilr_series.active', 'N')
->select('
ilr_series.series_id,
ilr_series.series_title,
ilr_series.active,
')
->from('
ilr_series,
ilr_league
')
->order_by('ilr_series.series_id', 'desc')
->get();
return $show_series;
Anyone know where I would need to put $num and $offset?
This function is a part of 2 other functions below that work in conjunction with each other. So I'll post those below as well. As all 3 link together.
Code: function a_show_seasons()
{
//$this->db->orderby('season_id', 'desc');
//$show_season = $this->db->getwhere('ilr_season', array('url_league_name' => $this->uri->segment(3)), '', '');
$show_season = $this->db
->where('ilr_league.url_league_name', $this->uri->segment(3))
->where('ilr_league.league_id = ilr_season.league_id')
->where('ilr_season.active', 'N')
->select('
ilr_season.season_id,
ilr_season.series_id,
ilr_season.season_title,
ilr_season.slots,
ilr_season.signup_open,
ilr_season.active,
ilr_season.car_name,
ilr_season.entry_fee,
ilr_series.series_title
')
->from('
ilr_season,
ilr_league
')
->order_by('ilr_season.season_id', 'desc')
->join('ilr_series', 'ilr_series.series_id = ilr_season.series_id')
->get();
return $show_season;
}
function a_show_events()
{
$show_events = $this->db
->where('ilr_league.url_league_name', $this->uri->segment(3))
->where('ilr_league.league_id = ilr_events.league_id')
->where('ilr_league.league_id = ilr_season.league_id')
->where('ilr_series.active', 'N')
->where('ilr_season.active', 'N')
->where('ilr_events.track_id = ilr_tracks.track_id')
->select('
ilr_events.schedule_id,
ilr_events.league_id,
ilr_events.user_id,
ilr_events.event_title,
ilr_events.season_id,
ilr_events.track_id,
ilr_events.event_date,
ilr_events.time,
ilr_season.season_title,
ilr_season.season_id,
ilr_season.series_id,
ilr_series.series_title,
ilr_series.series_id,
ilr_tracks.track_name,
ilr_tracks.config
')
->from('
ilr_season,
ilr_tracks,
ilr_league
')
->order_by('ilr_events.event_date', 'asc')
->join('ilr_series', 'ilr_series.series_id = ilr_season.series_id')
->join('ilr_events', 'ilr_events.season_id = ilr_season.season_id')
->get();
return $show_events;
}
Thanks
Shawn
Pagination, Problem passing per_page and offset in my query(SOLVED) - El Forum - 01-24-2010
[eluser]srpurdy[/eluser]
Ok I solved this,
I got hung up on my query working and being able to count without limiting the amount of results it outputs!
I needed to create a new function to count the specific entry's I wanted like below
Code: function count_results()
{
$count_res = $this->db
->where('ilr_league.url_league_name', $this->uri->segment(3))
->where('ilr_league.league_id = ilr_series.league_id')
->where('ilr_season.active', 'N')
->select('
ilr_series.series_id,
ilr_series.series_title,
ilr_series.active,
ilr_season.active
')
->from('
ilr_season,
ilr_league
')
->order_by('ilr_series.series_id', 'desc')
->join('ilr_series', 'ilr_series.series_id = ilr_season.series_id')
->get();
return $count_res;
}
I also added this to my a_show_seasons() function
Code: ->limit($num, $offset)
Also declaring this at the top of the function
Code: function a_show_seasons($num, $offset)
So my controller now looks like this
Code: $this->load->library('pagination');
$config['base_url'] = base_url(). 'archives/champs/' . $this->uri->segment(3);
$config['per_page'] = '5';
$config['uri_segment'] = '4';
$config['num_links'] = '4';
$data['series'] = $this->archives_model->a_show_series();
$data['season'] = $this->archives_model->a_show_seasons($config['per_page'],$this->uri->segment(4));
$data['count_res'] = $this->archives_model->count_results();
$data['query'] = $this->archives_model->a_show_events();
$config['total_rows'] = count($data['count_res']->result());
$this->pagination->initialize($config);
Maybe it will help someone, to create a function to count with instead of trying to use your original functions! dups!
|