1

I have a table, table_a, in my MySQL db. (I am using PHP for scripting)

Now I have created another table, after realizing its necessity, called table_b. For every row in table_a I want to insert some of its values into table_b, and then affix a timestamp (DATETIME type).

This is where I am:

$query = "INSERT INTO table_b('id_a', 'type_a', 'date_a') SELECT table_a.id, table_a.type, '$datetime'";

where $datetime is a time value (php).

I'm not sure this is going to work. Could someone tell me a correct way to do this.

(Aside: I am aware I'm not using prepared statements - that's for another day)

Thanks in advance.

4

1 回答 1

1

感谢所有评论,答案很简单:

$query = "INSERT INTO table_b(id_a, type_a, date_a) SELECT table_a.id, table_a.type, '$datetime' FROM table_a";

这会将 table_a 每一行的所需值添加到 table_b 中。

于 2013-10-14T17:56:27.790 回答