English 中文(简体)
将日期输入数据库
原标题:Storing the date in database

我的任务是将“报价”储存到一个数据库中(已经这样做),并显示其和复制;将其排出最近的说法。 假设“最近”我需要储存提交报价的日期/时间。

I am new to PHP and trying to learn, so I don t know how to exactly do this.

这里是将报价添加到数据库中的PHP。 表中有两栏,称为“报价”和“id”。 我也有必要为这个日期打一栏?

require( includes/connect.php );


    $quote = $_POST[ quote ];
    $quotes = mysql_real_escape_string($quote);


    mysql_query("INSERT INTO entries (quote) VALUES( $quotes )")
    or die(mysql_error());

我也怎样插入日期?

问题回答

如希望插入<条码>的现行。 日期

例如:

$query_auto = "INSERT INTO tablename (col_name, col_date) VALUE ( DATE: Auto CURDATE() , CURDATE() )";

但如果你手工操作,则应当使用:

$query_manual = "INSERT INTO tablename (col_name, col_date) VALUES ( DATE: Manual Date ,  2008-07-04 )";

<>>>>>

CREATE TABLE auto_ins
    (
        `MySQL_Function` VARCHAR(30),
        `DateTime` DATETIME,
        `Date` DATE,
        `Time` TIME,
        `Year` YEAR,
        `TimeStamp` TIMESTAMP
    );

INSERT INTO auto_ins
    (`MySQL_Function`, `DateTime`, `Date`, `Time`, `Year`, `TimeStamp`)
VALUES
    (“CURDATE()”, CURDATE(), CURDATE(), CURDATE(), CURDATE(), CURDATE());

“SCREEN

如果你只想最近的引文,你就可以简单地按其<条码><>d>/条码>确定结果。 DESC假设该补贴是一种自动加价。

是的,你需要第三列,才能说得最重(定义为日期或日期):

mysql_query("INSERT INTO entries (quote, most_recent) VALUES( $quotes , now())")

你们至少需要提交引书和报价表的两表。

create table users(id int primary key not null, username varchar(32),pwd varchar(32));

您可在电子邮件地址等表格上添加任何信息。

create table quotes (
id int not null , 
user_id integer,
quote_text varchar(256),
inserted_date timestamp default current_timestamp ,primary key (id));
alter table quotes add constraint fk_users foreign key(user_id) references users(id);

Otherwise feel free to modify them. It s not about php here its about DB design in general.

使用该守则:

require( includes/connect.php );


$quote = $_POST[ quote ];
$quotes = now().  -  .mysql_real_escape_string($quote);
// THIS WILL ADD THE DATE AND TIME TO YOUR $quotes STRING.


mysql_query("INSERT INTO entries (quote) VALUES( $quotes )")
or die(mysql_error());




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签