Welcome Guest, Not a member yet? Register   Sign In
Date manipulate question
#1

[eluser]Daniel_E9[/eluser]
I have a function in my model that gets everything from a database table and returns it. I then use this code to put my data into my template.

Code:
$article = $this->article->get_articles();
$this->parser-parse('index', array('article', $article));

Basically, one of the values I am getting is a field from the database with datetime. How do I amend that using date('y'm'd') etc before it goes into the parser?

Should be simple but I can't get it to work, thanks.
#2

[eluser]saidai jagan[/eluser]
Code:
$article = $this->article->get_articles();
$article['date_time']=date('Y-m-d',strtotime($article['datetime']));
$this->parser-parse('index', array('article', $article));
#3

[eluser]Daniel_E9[/eluser]
This was the first thing I tried and it still doesn't work saying 'Invalid argument supplied for foreach() in parser.php'.

This is my code, where article_date_time is the name of my field in the database.

ARTICLE MODEL:

Code:
function get_article() {
            $result = $this->db->get('blog_article', 2);
            return $result->result_array();
        }

CONTROLLER

Code:
function index() {
            $this->load->model('article');
            $article = $this->article->get_article();
            $article['article_date_time'] = date('Y-m-d', strtotime($article['article_date_time']));
        
            $this->parser->parse('blog', array('article' => $article));
        }

Any ideas?
#4

[eluser]saidai jagan[/eluser]
just use,
Code:
function get_article()
{
    $result = $this->db->get('blog_article', 2);
    $res_arr= $result->result_array();
    return $res_arr[0];
}

CONTROLLER
function index()
{
   $this->load->model('article');
   $article = $this->article->get_article();
print_r($article);
   $article['article_date_time'] = date('Y-m-d',strtotime($article['article_date_time']));
   $this->parser->parse('blog', array('article' => $article));
}
#5

[eluser]Daniel_E9[/eluser]
This doesn't work at all.. sorry Sad

I have the data returned in an array, so there must be a simple of way of just converting it. without modifying it in the model? I just don't understand why this line doesn't work:

Code:
$article['article_date_time'] = date('Y-m-d',strtotime($article['article_date_time']));

Any other ideas?
#6

[eluser]saidai jagan[/eluser]
[quote author="Daniel_E9" date="1258216699"]
Code:
$article['article_date_time'] = date('Y-m-d',strtotime($article['article_date_time']));

Any other ideas?[/quote]
$article = $this->model->get_values();
echo $article['article_date_time'];
#7

[eluser]saidai jagan[/eluser]
can u show me the array structure of $article.?
print_r($article);
#8

[eluser]Daniel_E9[/eluser]
Sure, I appreciate your help:

Code:
Array ( [0] => stdClass Object ( [article_id] => 1 [article_heading] => What a day [article_date_time] => 2006-09-04 10:30:17 [article_category] => General [article_mood] => N/A [article_music] => N/A [article_body] => Body text [article_visible] => n ) )

Thanks again
#9

[eluser]saidai jagan[/eluser]
hey there is a object (stdClass Object) in u r [0] th key.
#10

[eluser]Daniel_E9[/eluser]
I'm very new to this and not exactly sure what that means or does. I think I may be mis-understanding the context of how this array is being returned.

What would I need to do in that case to amend the date, or would I have to change it again somehow to manipulate the data correctly?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB