CodeIgniter Forums

Full Version: can you help... in Pagination I modified View and Controller function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
can you help... in Pagination I modified View and Controller function - I read some paragraphs from >>>

I am getting something like  >    // echo $this->pagination->create_links();  // this i inserted in View

‹ First<234

I plan to apply CSS3 but the problem is these all urls the DATA is the same ARE ALL 7 ROWS ALWAYS... AND NOT 2 PER PAGE // I PUT TWO 2 TO TEST IT



PHP Code:
    public function all()

       // Pagination from

       $config['base_url'] = 'http://localhost/repos/.../admin/videos/all/';

       $config['enable_query_strings'] = TRUE;

       $data['videos'] = $this->Video_model->get_list_public(); 

       $subject_options = array();
       $subject_options[0] = 'Select Subject';

       $subject_list $this->Subject_model->get_list(16);   //  $this->user_id
       foreach ($subject_list as $subject) {
           $subject_options[$subject->id] = $subject->name;

       $data['subject_options'] = $subject_options;

       $config['total_rows'] = count($data['videos']);
       $config['per_page'] = 2;
//echo $this->pagination->create_links();

        // Load Template

PHP Code:
       <td><?php echo $video->id?></td>
        <td><a class="fancybox fancybox.iframe" href="<?php echo $video->youtube_url?>"><img src="<?php echo trim($video->youtube_url); ?>/0.jpg" style="width: 150px;"><br><?php echo $video->title?></a></td>
        <td><?php echo $subject_options[$video->subject_id]; ?></td>
        <td><?php echo $video->youtube_published_year?></td>
        <td><?php echo $formatted_date?></td>
            <?php echo anchor('admin/videos/view/'.$video->id.'''View''class="btn btn-primary"'); ?>

<?php echo "<div id='paginationCI'>".$this->pagination->create_links()."</div>"?>

<?php else: ?>

    <p>No videos</p>

<?php endif; ?>
You need to add limit and offset to your SQL query.

In case you want to cheat.
PHP Code:
// Controller
public function page() {
$config['base_url'] = base_url('admin/ads/page');
$config['total_rows'] = $this->db->count_all('ads');
$config['per_page'] = 50;
$config['uri_segment'] = 4// You may need to change this
// You need to change segment(4,1) so it's matching the same number as your uri_segment
$offset = (intval($this->uri->segment(4,1))*$config['per_page'])-$config['per_page'];
$this->data['ads'] = $this->ads_model->get_all_ads($config['per_page'],$offset);

// Model
public function get_all_ads($limit,$offset) {
$query $this->db->get('ads',$limit,$offset);

// application/config/pagination.php - Default setttings
('BASEPATH') OR exit('No direct script access allowed');

$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<nav aria-label="Page navigation"><ul class="pagination">';
$config['full_tag_close'] = '</ul></nav>';
$config['prev_link'] = 'Prev.';
$config['next_link'] = 'Next';
$config['first_link'] = FALSE;
$config['last_link'] = FALSE;

$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';

$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';

$config['cur_tag_open'] = '<li><span>';
$config['cur_tag_close'] = '</span></li>';

$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['num_links'] = 4
When looking ad MySQL Select code be careful, the LIMIT offset and rows to return are backwards in CodeIgniter.
Thank you for your assistance

So Model edit required...  and also this 'ASC'); can be ('id', 'DESC'); .. ? // in model without error?

PHP Code:
// Model
public function get_all_ads($limit,$offset) {
   $query $this->db->get('ads',$limit,$offset);
   return $query->result();

also the file
// application/config/pagination.php - Default setttings

Not exist - but when created Code-igniter take use immediately everywhere Pagination exist? correct?
$config['total_rows'] = $this->db->count_all('ads');

needed two queries the first to get how many are all videos - rows???  how ^^ this work???

according to this ^^^ gets all rows of table but i want Only public[field public=1] videos count [exist and private[field public=0]]  what to do????
1. You don't need to sort it. If you already got a good natural order. But I just like to be sure.
2. It's just so you don't need to style it in every file. It it will have the same HTML if you use pagination again.
3. You can count it in PHP if you like, that's just how I did it.
$config['total_rows'] = $this->db->count_all('videos', 'public=1');

how can count - if have pagination and limit / offset, all videos in table currently having public=1(public is a table field can be 1 or 0)...???
Haven't tested it, but should work.
PHP Code:
$config['total_rows'] = $this->db->where('public',1)->count_all('videos'); 
PHP Code:
isset($config['total_rows']) ? '' : ($config['total_rows'] = $this->db->where('public',1)->count_all('videos')) ; 

This is valid so as total_rows calc only if Not isset????
Sure, but I don't know where you should have it set already. You only need it once in your code.
Pages: 1 2