Welcome Guest, Not a member yet? Register   Sign In
I need character pagination
#1

[eluser]prototype20[/eluser]
Hi guys,
i need character pagination library for CI.

(A, B, C, D, E...)
#2

[eluser]davidbehler[/eluser]
So build one Wink

To get a list of all characters from a - z use this
Code:
foreach(range('a', 'z') as $letter) {
    echo $letter;
}

What you have to do is make each letter a link to your controller/function where this letter is then used to select all entries starting with the submitted character. Something like this might work:

Let's assume you want to list books with id and title column.

View (views/books_list.php)
Code:
<?php
  foreach(range('a', 'z') as $letter) {
    echo ' '.anchor('books/books_list/'.$letter, $letter);
  }
?>
<b>Books:</b>
<table>
  <tr>
    <td>
      ID
    </td>
    <td>
      Title
    </td>
  </tr>
  &lt;?php
    foreach($books as $book) {
  ?&gt;
    <tr>
      <td>
        &lt;?php echo $book['id']; ?&gt;
      </td>
      <td>
        &lt;?php echo $book['title']; ?&gt;
      </td>
    </tr>
  &lt;?php
    }
  ?&gt;
  ?&gt;
</table>
Controller (controllers/books.php):
Code:
&lt;?php
  class Books extends Controller {
    function Books () {
      parent:Controller();
    }

    function books_list($char = FALSE) {
      $this->load->model('Books_model');
      $data = array();
      $data['books'] = $this->Books_model->get_list($char);
      $this->load->view('books_list', $data);
    }
  }

Model (models/books_model.php):
Code:
&lt;?php
  class Books_model extends Model {
    function Books_model() {
      parent::Model();
    }

    function get_list($char = FALSE) {
      $this->db->from('books');
      if($char !== FALSE) {
        $this->db->like('title', $char, 'after');
      }
      $this->db->order_by('title', 'asc');
      $result = $this->db->get();
      if($result->num_rows() > 0) {
        return $result->result_array();
      } else {
        return array();
      }
    }
  }

This is untested, but I guess you can see what I'm doing and use this to solve your problem.
#3

[eluser]prototype20[/eluser]
Thanks! :-)




Theme © iAndrew 2016 - Forum software by © MyBB