Welcome Guest, Not a member yet? Register   Sign In
Pagination: The "Back" button or the "Page 1" button not working after changing pages
#1

What I'm trying to do is create a pagination function. I have successfully created that. It works. The URI segment changes and everything. It's perfect. However, there is a small problem. When I press the "next" button or press another number to go to the next page, the "page 1" is still highlighted for some reason. I can't click it to go to the first page. The "Previous" button show up either. So after I go to a second page or any other page, other than 1, I cannot get back to the first page. The only way I can go back to the first page is by changing the URI segment.

I couldn't find an answer to this specific question, so any help is highly appreciated. Thanks.

My Model:

PHP Code:
public function record_count_sitelog()
{
    
$uid $this->uri->segment(4);
    return 
$this->db->get_where('site_log', array('uid' => $uid))->num_rows();
}

public function 
fetch_users_sitelog($limit$start)
{
    
$this->db->order_by("time""desc"); //ordering it in descending order
    
$uid $this->uri->segment(4);
    
$this->db->limit($limit$start);

    
$query $this->db->get_where('site_log', array('uid' => $uid));

    if (
$query->num_rows() > 0) {
        foreach (
$query->result() as $row) {
            
$data[] = $row;
        }
        return 
$data;
    }
    return 
false;

My Controller:
PHP Code:
public function site_log() {
    
$uid $this->uri->segment(4);

    
$data = array( 'uid' => $uid
    
);

    
$this->load->model('Model_Admin_Pagination');
    
$this->load->library('pagination');
    
$this->load->library('table');

    
$config = array();
    
$config["base_url"] = base_url() . "admin/users/site_log/"$uid ."/";
    
$this->db->select('*');
    
$config["total_rows"] = $this->Model_Admin_Pagination->record_count_sitelog();
    
$config["per_page"] = 20;
    
$config["uri_segment"] = 4;
    
$config["num_links"] = 3;
    
$config['records'] = $this->db->select('*');
    
//styling it
    
$config['full_tag_open'] = '<div class="pull-right"> <ul class="pagination">';
    
$config['full_tag_close'] = '</div></ul>';
    
$config['num_tag_open'] = '<li>';
    
$config['num_tag_close'] = '</li>';
    
$config['next_link'] = '→';
    
$config['next_tag_open'] = '<li>';
    
$config['next_tag_close'] = '</li>';
    
$config['prev_link'] = '←';
    
$config['cur_tag_open'] = '<li class="active"><a>';
    
$config['cur_tag_close'] = '</li></a>';
    
$config['prev_tag_open'] = '<li>';
    
$config['prev_tag_close'] = '</li>';
    
$config['last_link'] = '»';
    
$config['last_tag_open'] = '<li>';
    
$config['last_tag_close'] = '</li>';
    
$config['first_link'] = '«';
    
$config['first_tag_open'] = '<li>';
    
$config['first_tag_close'] = '</li>';
    
//end styling it

    
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
    
$data["results"] = $this->Model_Admin_Pagination->
    
fetch_users_sitelog($config["per_page"], $page);
    
$data["links"] = $this->pagination->create_links();

    
$this->pagination->initialize($config);

    
$this->load->view('admin/includes/header');
    
$this->load->view('admin/view_site_log'$data);

My View:

PHP Code:
<?php
if (is_array($results))
{
    foreach (
$results as $data) { ?>
        <div> <!--class="col-md-6 col-sm-6"-->
            <div class="well pretty-text">
                <p>
                    <h3><font color="#708090">Time:</font> <?php echo date("g:i A"strtotime($data->time)). ' on ' date("F j, Y"strtotime($data->time)) ?><br></h3>
                    <b>Current URL:</b> <?php echo $data->current_url ?><br>
                    Referrer: <?php echo $data->referrer ?><br>
                    <b>Browser:</b> <?php echo $data->browser ?><br>

                    Mobile: <?php echo $data->mobile ?><br>
                    <b>Platform:</b> <?php echo $data->platform ?><br>
                <b>User Agent:</b> <?php echo $data->user_agent ?>

                </p>
            </div>
        </div>
    <?php } } ?>

<?php  echo $this->pagination->create_links(); ?>
Reply
#2

It looks like your uri_segment setting may be wrong (shouldn't it be 5 instead of 4?).

Also, you shouldn't use font tags in your HTML. They were deprecated in HTML4 16 years ago and aren't valid in HTML5. You can use a span and apply the color to the span in CSS, which would also make it easier to change later, if necessary.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB