[eluser]kyleect[/eluser]
Here are the basics. I have two tables: posts and users. What I want to do is have both a raw timestamp and a formatted date. I figured the model is the best place for this data transformation which is why I used the AS keyword. However, I seem to be running in to some issues:
1) I'm getting this error:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: datetime
Filename: models/Post.php
Line Number: 83
however this is is the array it's referring to:
Code:
Array
(
[0] => Array
(
[id] => 1
[body] => fasdfadf
[user_id] => 1
[datetime] => 1241405669
[username] => dev
)
[1] => Array
(
[id] => 1
[body] => asdfadsf
[user_id] => 1
[datetime] => 1241405666
[username] => dev
)
[2] => Array
(
[id] => 1
[body] => fdf
[user_id] => 1
[datetime] => 1241405663
[username] => dev
)
[3] => Array
(
[id] => 1
[body] => test
[user_id] => 1
[datetime] => 1241405104
[username] => dev
)
[datetime] => 1969/12/31 @ 6:00:00 pm
)
These appear to have a datetime index.
2) What is with the actual index 'datetime' with a formatted date?
Any help would be greatly appreciated.
-------------------------------
Method from the Post model:
Code:
public function river($limit)
{
$query = $this->db->query("
SELECT
p.id,
p.body,
p.user_id,
p.timestamp AS datetime,
u.id,
u.username
FROM
posts p,
users u
WHERE
u.id = p.user_id
ORDER BY p.timestamp DESC
LIMIT 0, {$limit}
");
if ($query->num_rows() > 0)
{
$results = $query->result_array();
$results['datetime'] = date('Y/m/d @ g:i:s a', $results['datetime']);
return $results;
}
else
{
return false;
}
}
Code from controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Home
*
* Home is always the default controller. It's what's displayed as the root index.
*
*/
// ------------------------------------------------------------------------
/**
* @package CI1.7_kyct
* @subpackage controllers
**/
class Home extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Post');
}
function index()
{
$data['river'] = $this->Post->river(10);
$this->load->view('home', $data);
}
}
?>