0

I'm attempting to modify a date field from my database before it gets outputted to the view, but I'm not having much luck. This code doesn't seem to work, what am I doing wrong?

function get_journal_entry($id)
    {
        $sql = 'SELECT * FROM journal WHERE user_id = '.$this->tank_auth->get_user_id().' AND id = '.$id;
        $query = $this->db->query($sql);

        $query['created'] = date("c", strtotime($query['created']));


        return $query->row_array();
    }

2 Answers 2

3

$this->db->query returns a query object, not your results. You need to modify the row after calling $query->row_array.

$query = $this->db->query($sql);
$result = $query->row_array();
$result['created'] = date("c", strtotime($result['created']));
return $result;
0
1

Another version of the code, which may work:

function get_journal_entry($id)
{
    $sql = 'SELECT * FROM journal WHERE user_id = ' . intval($this->tank_auth->get_user_id()) . ' AND id = ' . intval($id);
    $row = $this->db->query($sql)->row_array();
    $row['created'] = date("c", strtotime($row['created']));
    return $row;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.