Welcome Guest, Not a member yet? Register   Sign In
Post is X days old with Pagination
#1

[eluser]Stenson[/eluser]
I am trying to find a way to show the 'Age' of the row stored within the Pagination. For example instead of showing the timestamp as the date/time, I want to show it as 'Posted 10 minutes ago', '2 days ago' etc..

My problem is that my data is displayed using the 'foreach' statement which echos '$row->lectureCreated' but this needs to be changed somehow.

How would i go about doing this? Sorry if this still seems very unclear...

My function within the Controller is this:-

Code:
function admin_viewlectures() {
        if($this->session->userdata('admin_is_logged_in') != TRUE) {
            redirect('login/index');
        } else {
            $this->load->library('pagination');
            
            $config['base_url'] = 'http://localhost:8888/****/index.php/site/admin_viewlectures/';
            $config['total_rows'] = $this->db->count_all('lectures');
            $config['per_page'] = '12';

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

            $data['pagination_links'] =  $this->pagination->create_links();
            $this->load->model('lecture_model');
            $data['lecture_query'] = $this->lecture_model->read($config['per_page'], $this->uri->segment(3));
            
            
            $this->load->view('admin/viewlectures', $data);
        }
    }

View

Code:
<?php if(isset($lecture_query)) : foreach($lecture_query->result() as $row) : ?>
                            <li>
                            <div class="leftarea"> &lt;!-- Left Area Start --&gt;
                                <div class="posttitle">&lt;?php echo $row->lectureTitle; ?&gt;</div>
                                   <div class="course">&lt;?php echo $row->courseID; ?&gt;</div>
                                <div class="module">&lt;?php echo $row->moduleID; ?&gt;</div>
                                <div class="created">&lt;?php echo $row->lectureCreated; ?&gt;</div>
                            </div> &lt;!-- Left Area End --&gt;
                            <div class="rightarea"> &lt;!-- Right Area Start --&gt;
                                <div class="listoptions">
                                    &lt;?php echo anchor("lecture/editLecture/$row->lectureID", '<span class="hide">Edit</span>',
                                        'class="editbutton" title="Edit ' . $row->lectureTitle . '"'); ?&gt;
                                    &lt;?php echo anchor("lecture/deleteLecture/$row->lectureID", '<span class="hide">Remove</span>',
                                         'class="removebutton" title="Delete ' . $row->lectureTitle . '"'); ?&gt;
                                </div>
                            </div>
                            </li>
                            &lt;?php endforeach; ?&gt;
                               &lt;?php else : ?&gt;    
                            <h2>No records were returned.</h2>
                            &lt;?php endif; ?&gt;
#2

[eluser]Alex C.[/eluser]
What's about buildig the difference between time() and the timestamp of the database entry ?

If it(the difference) is between 0 and 60 you take "x" seconds, if it's bigger or equal 60 AND it is less than 3600 (1 hour) you take "x" minutes , and so on ..

So you are building a string in the foreach loop and echo this one.
#3

[eluser]Stenson[/eluser]
Thanks Alex C.

I wasn't really thinking about writing it within the view file, but it works just as well!




Theme © iAndrew 2016 - Forum software by © MyBB