Welcome Guest, Not a member yet? Register   Sign In
changing unixtime to time in controller
#1

[eluser]cleansugar[/eluser]
model:
Code:
function getData()
    {
        //Query the data table for every record and row
        $query = $this->db->get('board');
        
        if ($query->num_rows() == 0)
        {
            show_error('Database is empty!');
        }else{
            return $query->result();
        }
    }
controller:
Code:
function index()
    {
        $data['result'] = $this->board_model->getData();
        echo $data['result']->time;
                $data['result']->time = date('Y-m-d h:i:s', $data['result']->time);

        $this->load->view('board_view',$data);
    }
db:
id int
author tinytext
subject tinytext
time int

I want to change time from model in contorller.

If I want unixtime(int) to text(2009-Jan-1 11:12:11), what can I change my source?

A PHP Error was encountered
Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/board.php

Line Number: 15
#2

[eluser]slowgary[/eluser]
I could be wrong but I think the problem is that you are returning a result() object (which is a collection of rows) from your model, then you're trying to access "->time" (which is a property of a single row) in your controller.

You'll probably need to loop through the result of $this->board_model->getData(); and set each row's time property.
#3

[eluser]cleansugar[/eluser]
Code:
function index()
    {
        $data['result'] = $this->board_model->getData();
        if ($data['result']->num_rows() > 0)
        {
               foreach ($data['result']->result() as $row)
               {
                   $row->time = date('Y-m-d h:i:s', $row->time);
            }
        }
                
        $this->load->view('board_view',$data);

This source also returns object error.

Do you know how to correct this, please?
#4

[eluser]slowgary[/eluser]
Try posting your errors specifically. I'll guess again...

You're returning
Code:
$query->result()
in your model and assigning it to
Code:
$data['result']
then in your controller you're trying to access
Code:
$data['result']->result()
which is basically like saying
Code:
$query->result()->result()

But maybe I'm wrong. Does the error say "Server is currently down for routine maintenance" ?




Theme © iAndrew 2016 - Forum software by © MyBB