0

我的数据库中还有一个日期字段,其日期数据类型未设置为 null

这是我的观点——我应该在这里添加一些额外的东西吗?

 foreach($blogs AS $viewData)
  {
$id = $viewData->id;
$title = $viewData->title;
$body = $viewData->body;
$username = $viewData->username;
$date = $viewData->date;

?>

   <b> <?=$title?></b>
    <p><?=$body?></p>

      <p>posted by:<?=$username?></p>
      <p>date: <?=$date?></p>

<hr>

这是我插入数据库的模型中的函数...

   public function insert_entry()
{
    $this->title = $this->input->post('title');
        $this->body = $this->input->post('text');
        $this->username = $this->session->userdata('username'); 
        $this->date = time();// is there something I should change here?

        $this->db->insert('blogs', $this);

     }
4

1 回答 1

0

how do you insert into your blogs table? show query

you should use something like this to have proper values in 'date' field:

mysql_query("INSERT INTO blogs(title,body,username,date) VALUES('$title','$body','$username',NOW())");

or if you want to set manual timestamp do something like this:

mysql_query("INSERT INTO blogs(title,body,username,date) VALUES('$title','$body','$username','".date("Y-m-d H:i:s", $your_timestamp)."')");

this is the way to insert proper date/datetime values

于 2012-12-12T22:02:28.057 回答