Hello I really need your help Im new to codeigniter and I need to implement a pagination alphabetically from a-z i don't know where to start .. I hope you can help me.
Here's an example of what it should look like, ofcourse this is not a complete code but it's more like a guide on how to accomplish this.
### in your controller
$data['alpha'] = range('a', 'z');
// get the filter value from $_GET array
$alpha_filter = $this->input->get('alpha_filter');
// check if it's actually an alpha; otherwise it's set to null (no filter applied).
if( ! in_array($alpha_filter, $data['alpha'])) $alpha_filter = NULL;
// pass the filter to your model method so it adjusts the results approperiatly
// Note: we're still passing the limit & offset so even with alpha_filter we're still able to paginate the result.
$data['records'] = $this->names_model->get_names($limit, $offset, $alpha_filter);
### in your view
foreach( $alpha as $letter ) {
echo anchor("controller/method?alpha_filter={$letter}", $letter);
}
you can make a controller function which take 1 parameter $character, then put all alphabetical in array then you can loop array and echo links like this:
foreach ($char in $arr_char)
{
echo "<a href='url_to_your_contoller_function/$char' > $char</a>";
}
and in your contoller function:
function your_contoller_function($char)
{
//write your model query here to get all content which related to this character.
}