I am trying to change the format of a date that is being selected from a MySQL database but it is returning an error. I've looked online but I can't work our what I'm doing wrong.
The code that I am using in my model is as follows:
Public function get_news()
{
$this->db->select('id, text');
$this->db->select("DATE_FORMAT(date,'%W %D %M %Y')", FALSE);
$this->db->limit(10);
$this->db->order_by('date', 'desc');
$query = $this->db->get('news');
$result = $query->result_array();
return $result;
}
The error is:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: date
Filename: views/news.php
Line Number: 22
Backtrace:
File: C:\xampp\htdocs\tsh\CI\application\views\news.php
Line: 22
Function: _error_handler
File: C:\xampp\htdocs\tsh\CI\application\controllers\home.php
Line: 99
Function: view
File: C:\xampp\htdocs\tsh\public_html\index.php
Line: 292
Function: require_once
View:
<?php foreach($news as $news_item) { ?>
<article class="article_text">
<p class="segment_headding"><?php echo $news_item['date']; ?></p>
<?php echo $news_item['text']; ?>
</article>
<?php } ?>
I'm sure it is just something silly that I've done wrong but I just can't see it.