Welcome Guest, Not a member yet? Register   Sign In
MySql Date HELL!!!
#1

[eluser]Unknown[/eluser]
Good evening!

I've the spent the better part of today - in between episodes of "The Office" - figuring out how to get MySql to auto insert a date into my blog and my comments. I've read several other posts and tried several techniques to no avail. With the exception of a CSS sheet and some minor styling, the documents are exactly like the video tutorials. Can someone please show me how to fix this? Any help would be greatly appreciated.

This is what I have:

blog.php file
Code:
<?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
        $this->load->scaffolding('entries');
        
        $this->load->helper('url');
        $this->load->helper('form');

    }

    function index()
    {
        $data['title'] = "This is my title";
        $data['heading'] = "This is my heading";
        $data['query'] = $this->db->get('entries');
        
        $this->load->view('blog_view', $data);
    }
    
    function comments()
    {
        $data['title'] = "My Comment Title";
        $data['heading'] = "My Comment Heading";
        $this->db->where('entry_id', $this->uri->segment(3));
        $data['query'] = $this->db->get('comments');

        $this->load->view('comment_view', $data);
    }
    
    function comment_insert()
    {
        $this->db->insert('comments', $_POST);
        
        redirect('blog/comments/'.$_POST['entry_id']);
    }
}

?>

comment_view.php
Code:
<h1>&lt;?=$heading?&gt;</h1>
    
            &lt;?php if ($query->num_rows() > 0):?&gt;
        
                &lt;?php foreach($query->result() as $row): ?&gt;
    
                <p>&lt;?=$row->body?&gt;</p>
                <p>&lt;?=$row->author?&gt;</p>

                <hr>
    
    
                &lt;?php endforeach; ?&gt;
        
            &lt;?php endif; ?&gt;
    
            <p>&lt;?=anchor('blog', 'Back to Blog');?&gt;</p>
    
            &lt;?=form_open('blog/comment_insert');?&gt;
    
            &lt;?=form_hidden('entry_id', $this->uri->segment(3));?&gt;
    
            <p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea&gt;</p>
            <p>&lt;input type="text" name="author" /&gt;</p>
            <p>&lt;input type="submit" value="Submit Comment" /&gt;</p>
    
            &lt;/form&gt;

blog_view.php
Code:
<h1>&lt;?=$heading?&gt;</h1>
    
            &lt;?php foreach($query->result() as $row): ?&gt;
    
            <h2>&lt;?=$row->date?&gt;</h2>
            <h3>&lt;?=$row->title?&gt;</h3>
            <p>&lt;?=$row->body?&gt;</p>
    
            <p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>

            <hr>
    
            &lt;?php endforeach; ?&gt;
#2

[eluser]John_Betong[/eluser]
[quote author="Conspirator" date="1206425380"]Good evening!

I've the spent the better part of today - in between episodes of "The Office" - figuring out how to get MySql to auto insert a date into my blog and my comments. I've read several other posts and tried several techniques to no avail. With the exception of a CSS sheet and some minor styling, the documents are exactly like the video tutorials. Can someone please show me how to fix this? Any help would be greatly appreciated.
[/quote]
&nbsp;
&nbsp;
There are numerous solutions to auto insert a date and I think the easiest is to use PhpMyAdmi to add a date field to your table with a type TIMESTAMP then to check the insert TIMESTAMP on update or insert TIMESTAMP on create (from memory)
&nbsp;
&nbsp;
A quick Google search brought up this solution.
[quote]
Re: phpmyadmin/MySQL - dynamic date field?
>I'm doing a php/MySQL page that reads data out of a MySQL database.
>Longer term, I'll do a data-entry screen allowing me to modify the
>database or add new records. For now, I'm just using phpmyadmin to data
>enter stuff.


>Is there a way to set up a date field, Last_Update, that would
>automatically update to today's date any time a record was added or
>changed using phpmyadmin?


This is the purpose of the field type 'timestamp'. If you want
only the date portion, you can get it with date_format() in the
MySQL query.

The *first* timestamp field will be updated to the current time if
the record is changed, and that field isn't explicitly set. If a
record is inserted, the timestamp field will be the current time
unless another non-null value is explicitly inserted (insert null
or leave the field out of the field list for insert).

Leave off the "using phpmyadmin" part. You get that behavior if
the record is changed with a query, with or without phpmyadmin.
*Can* you modify just one field with phpmyadmin? If you type in
an explicit query, yes, if you use neato GUI stuff, you may be
setting all the fields you didn't change back to the values they
had before, which defeats the action of the timestamp.

Gordon L. Burditt
[/quote[
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB