我试图将数据库中的一个表中的某些列复制到新创建的表中 - 但没有成功。
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<?
// Retrieve data from database
$table = "CREATE TABLE bawtry_stock
(
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID)
)";
mysql_query($table);
?>
<?
$insert = "INSERT INTO bawtry_stock (
product_id,
title,
wholesale_price,
quantity_c_size_26,
quantity_c_size_28,
quantity_c_size_30,
quantity_c_size_32,
quantity_c_size_33,
quantity_c_size_34,
quantity_c_size_35,
quantity_c_size_355,
quantity_c_size_36,
quantity_c_size_365,
quantity_c_size_37,
quantity_c_size_375,
quantity_c_size_38,
quantity_c_size_385,
quantity_c_size_39,
quantity_c_size_395,
quantity_c_size_40,
quantity_c_size_405,
quantity_c_size_41,
quantity_c_size_415,
quantity_c_size_42,
quantity_c_size_425,
quantity_c_size_43,
quantity_c_size_435,
quantity_c_size_44,
quantity_c_size_445,
quantity_c_size_45,
quantity_c_size_455,
quantity_c_size_46,
quantity_c_size_465,
quantity_c_size_47,
quantity_c_size_475,
quantity_c_size_48,
quantity_c_size_485,
kids_uk_i_3,
kids_uk_i_35,
kids_uk_i_4,
kids_uk_i_45,
kids_uk_i_5,
kids_uk_i_55,
kids_uk_i_6,
kids_uk_i_65,
kids_uk_i_7,
kids_uk_i_75,
kids_uk_i_8,
kids_uk_i_85,
kids_uk_j_9,
kids_uk_j_95,
kids_uk_j_10,
kids_uk_j_105,
kids_uk_j_11,
kids_uk_j_115,
kids_uk_j_12,
kids_uk_j_125,
kids_uk_j_13,
kids_uk_j_135,
kids_uk_j_1,
kids_uk_j_15,
kids_uk_j_2,
kids_uk_j_25,
kids_uk_j_3,
kids_uk_j_35,
kids_uk_s_3,
kids_uk_s_35,
kids_uk_s_4,
kids_uk_s_45,
kids_uk_s_5,
kids_uk_s_55,
kids_uk_s_6,
kids_uk_s_65,
kids_uk_s_7,
kids_uk_s_75,
kids_uk_s_8,
kids_uk_s_85,
kids_c_17,
kids_c_18,
kids_c_19,
kids_c_20,
kids_c_21,
kids_c_22,
kids_c_23,
kids_c_24,
kids_c_25,
kids_c_26,
kids_c_27,
kids_c_28,
kids_c_29,
kids_c_30,
kids_c_31,
kids_c_32,
kids_c_33,
kids_c_34,
kids_c_35,
kids_c_36,
kids_c_37,
kids_c_38,
kids_c_39,
kids_c_40,
kids_c_41,
kids_c_42,
kids_c_43,
quantity_size_one,
quantity_size_1,
quantity_size_2,
quantity_size_3,
quantity_size_4,
quantity_size_5,
quantity_size_6,
quantity_size_7,
quantity_size_8,
quantity_size_9,
quantity_size_10,
quantity_size_11,
quantity_size_12,
quantity_size_13,
quantity_size_15,
quantity_size_25,
quantity_size_35,
quantity_size_45,
quantity_size_55,
quantity_size_65,
quantity_size_75,
quantity_size_85,
quantity_size_95,
quantity_size_105,
quantity_size_115,
quantity_size_125 )
SELECT product_id,
title,
wholesale_price,
quantity_c_size_26,
quantity_c_size_28,
quantity_c_size_30,
quantity_c_size_32,
quantity_c_size_33,
quantity_c_size_34,
quantity_c_size_35,
quantity_c_size_355,
quantity_c_size_36,
quantity_c_size_365,
quantity_c_size_37,
quantity_c_size_375,
quantity_c_size_38,
quantity_c_size_385,
quantity_c_size_39,
quantity_c_size_395,
quantity_c_size_40,
quantity_c_size_405,
quantity_c_size_41,
quantity_c_size_415,
quantity_c_size_42,
quantity_c_size_425,
quantity_c_size_43,
quantity_c_size_435,
quantity_c_size_44,
quantity_c_size_445,
quantity_c_size_45,
quantity_c_size_455,
quantity_c_size_46,
quantity_c_size_465,
quantity_c_size_47,
quantity_c_size_475,
quantity_c_size_48,
quantity_c_size_485,
kids_uk_i_3,
kids_uk_i_35,
kids_uk_i_4,
kids_uk_i_45,
kids_uk_i_5,
kids_uk_i_55,
kids_uk_i_6,
kids_uk_i_65,
kids_uk_i_7,
kids_uk_i_75,
kids_uk_i_8,
kids_uk_i_85,
kids_uk_j_9,
kids_uk_j_95,
kids_uk_j_10,
kids_uk_j_105,
kids_uk_j_11,
kids_uk_j_115,
kids_uk_j_12,
kids_uk_j_125,
kids_uk_j_13,
kids_uk_j_135,
kids_uk_j_1,
kids_uk_j_15,
kids_uk_j_2,
kids_uk_j_25,
kids_uk_j_3,
kids_uk_j_35,
kids_uk_s_3,
kids_uk_s_35,
kids_uk_s_4,
kids_uk_s_45,
kids_uk_s_5,
kids_uk_s_55,
kids_uk_s_6,
kids_uk_s_65,
kids_uk_s_7,
kids_uk_s_75,
kids_uk_s_8,
kids_uk_s_85,
kids_c_17,
kids_c_18,
kids_c_19,
kids_c_20,
kids_c_21,
kids_c_22,
kids_c_23,
kids_c_24,
kids_c_25,
kids_c_26,
kids_c_27,
kids_c_28,
kids_c_29,
kids_c_30,
kids_c_31,
kids_c_32,
kids_c_33,
kids_c_34,
kids_c_35,
kids_c_36,
kids_c_37,
kids_c_38,
kids_c_39,
kids_c_40,
kids_c_41,
kids_c_42,
kids_c_43,
quantity_size_one,
quantity_size_1,
quantity_size_2,
quantity_size_3,
quantity_size_4,
quantity_size_5,
quantity_size_6,
quantity_size_7,
quantity_size_8,
quantity_size_9,
quantity_size_10,
quantity_size_11,
quantity_size_12,
quantity_size_13,
quantity_size_15,
quantity_size_25,
quantity_size_35,
quantity_size_45,
quantity_size_55,
quantity_size_65,
quantity_size_75,
quantity_size_85,
quantity_size_95,
quantity_size_105,
quantity_size_115,
quantity_size_125
'1'
FROM product
ORDER BY product_id ASC";
mysql_query($insert);
?>
目前只会创建新表,但不会将列数据添加到新数据中。总而言之,我试图从&#39;产品&#39;中复制列数据。 (表)并将它们插入&#39; bawtry_stock&#39;。
任何帮助都将不胜感激。
谢谢,
更新
使用此代码解决了这个问题:
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<?
// Retrieve data from database
$table = "CREATE TABLE bawtry_stock
(
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID),
product_id mediumint(6) NOT NULL,
title varchar (255) NOT NULL,
wholesale_price varchar(50) NOT NULL,
quantity_c_size_26 mediumint(30) NOT NULL,
quantity_c_size_28 mediumint(30) NOT NULL,
quantity_c_size_30 mediumint(30) NOT NULL,
quantity_c_size_32 mediumint(30) NOT NULL,
quantity_c_size_33 mediumint(30) NOT NULL,
quantity_c_size_34 mediumint(30) NOT NULL,
quantity_c_size_35 mediumint(30) NOT NULL,
quantity_c_size_355 mediumint(30) NOT NULL,
quantity_c_size_36 mediumint(30) NOT NULL,
quantity_c_size_365 mediumint(30) NOT NULL,
quantity_c_size_37 mediumint(30) NOT NULL,
quantity_c_size_375 mediumint(30) NOT NULL,
quantity_c_size_38 mediumint(30) NOT NULL,
quantity_c_size_385 mediumint(30) NOT NULL,
quantity_c_size_39 mediumint(30) NOT NULL,
quantity_c_size_395 mediumint(30) NOT NULL,
quantity_c_size_40 mediumint(30) NOT NULL,
quantity_c_size_405 mediumint(30) NOT NULL,
quantity_c_size_41 mediumint(30) NOT NULL,
quantity_c_size_415 mediumint(30) NOT NULL,
quantity_c_size_42 mediumint(30) NOT NULL,
quantity_c_size_425 mediumint(30) NOT NULL,
quantity_c_size_43 mediumint(30) NOT NULL,
quantity_c_size_435 mediumint(30) NOT NULL,
quantity_c_size_44 mediumint(30) NOT NULL,
quantity_c_size_445 mediumint(30) NOT NULL,
quantity_c_size_45 mediumint(30) NOT NULL,
quantity_c_size_455 mediumint(30) NOT NULL,
quantity_c_size_46 mediumint(30) NOT NULL,
quantity_c_size_465 mediumint(30) NOT NULL,
quantity_c_size_47 mediumint(30) NOT NULL,
quantity_c_size_475 mediumint(30) NOT NULL,
quantity_c_size_48 mediumint(30) NOT NULL,
quantity_c_size_485 mediumint(30) NOT NULL,
kids_uk_i_3 mediumint(30) NOT NULL,
kids_uk_i_35 mediumint(30) NOT NULL,
kids_uk_i_4 mediumint(30) NOT NULL,
kids_uk_i_45 mediumint(30) NOT NULL,
kids_uk_i_5 mediumint(30) NOT NULL,
kids_uk_i_55 mediumint(30) NOT NULL,
kids_uk_i_6 mediumint(30) NOT NULL,
kids_uk_i_65 mediumint(30) NOT NULL,
kids_uk_i_7 mediumint(30) NOT NULL,
kids_uk_i_75 mediumint(30) NOT NULL,
kids_uk_i_8 mediumint(30) NOT NULL,
kids_uk_i_85 mediumint(30) NOT NULL,
kids_uk_j_9 mediumint(30) NOT NULL,
kids_uk_j_95 mediumint(30) NOT NULL,
kids_uk_j_10 mediumint(30) NOT NULL,
kids_uk_j_105 mediumint(30) NOT NULL,
kids_uk_j_11 mediumint(30) NOT NULL,
kids_uk_j_115 mediumint(30) NOT NULL,
kids_uk_j_12 mediumint(30) NOT NULL,
kids_uk_j_125 mediumint(30) NOT NULL,
kids_uk_j_13 mediumint(30) NOT NULL,
kids_uk_j_135 mediumint(30) NOT NULL,
kids_uk_j_1 mediumint(30) NOT NULL,
kids_uk_j_15 mediumint(30) NOT NULL,
kids_uk_j_2 mediumint(30) NOT NULL,
kids_uk_j_25 mediumint(30) NOT NULL,
kids_uk_j_3 mediumint(30) NOT NULL,
kids_uk_j_35 mediumint(30) NOT NULL,
kids_uk_s_3 mediumint(30) NOT NULL,
kids_uk_s_35 mediumint(30) NOT NULL,
kids_uk_s_4 mediumint(30) NOT NULL,
kids_uk_s_45 mediumint(30) NOT NULL,
kids_uk_s_5 mediumint(30) NOT NULL,
kids_uk_s_55 mediumint(30) NOT NULL,
kids_uk_s_6 mediumint(30) NOT NULL,
kids_uk_s_65 mediumint(30) NOT NULL,
kids_uk_s_7 mediumint(30) NOT NULL,
kids_uk_s_75 mediumint(30) NOT NULL,
kids_uk_s_8 mediumint(30) NOT NULL,
kids_uk_s_85 mediumint(30) NOT NULL,
kids_c_17 mediumint(30) NOT NULL,
kids_c_18 mediumint(30) NOT NULL,
kids_c_19 mediumint(30) NOT NULL,
kids_c_20 mediumint(30) NOT NULL,
kids_c_21 mediumint(30) NOT NULL,
kids_c_22 mediumint(30) NOT NULL,
kids_c_23 mediumint(30) NOT NULL,
kids_c_24 mediumint(30) NOT NULL,
kids_c_25 mediumint(30) NOT NULL,
kids_c_26 mediumint(30) NOT NULL,
kids_c_27 mediumint(30) NOT NULL,
kids_c_28 mediumint(30) NOT NULL,
kids_c_29 mediumint(30) NOT NULL,
kids_c_30 mediumint(30) NOT NULL,
kids_c_31 mediumint(30) NOT NULL,
kids_c_32 mediumint(30) NOT NULL,
kids_c_33 mediumint(30) NOT NULL,
kids_c_34 mediumint(30) NOT NULL,
kids_c_35 mediumint(30) NOT NULL,
kids_c_36 mediumint(30) NOT NULL,
kids_c_37 mediumint(30) NOT NULL,
kids_c_38 mediumint(30) NOT NULL,
kids_c_39 mediumint(30) NOT NULL,
kids_c_40 mediumint(30) NOT NULL,
kids_c_41 mediumint(30) NOT NULL,
kids_c_42 mediumint(30) NOT NULL,
kids_c_43 mediumint(30) NOT NULL,
quantity_size_one mediumint(30) NOT NULL,
quantity_size_1 mediumint(30) NOT NULL,
quantity_size_2 mediumint(30) NOT NULL,
quantity_size_3 mediumint(30) NOT NULL,
quantity_size_4 mediumint(30) NOT NULL,
quantity_size_5 mediumint(30) NOT NULL,
quantity_size_6 mediumint(30) NOT NULL,
quantity_size_7 mediumint(30) NOT NULL,
quantity_size_8 mediumint(30) NOT NULL,
quantity_size_9 mediumint(30) NOT NULL,
quantity_size_10 mediumint(30) NOT NULL,
quantity_size_11 mediumint(30) NOT NULL,
quantity_size_12 mediumint(30) NOT NULL,
quantity_size_13 mediumint(30) NOT NULL,
quantity_size_15 mediumint(30) NOT NULL,
quantity_size_25 mediumint(30) NOT NULL,
quantity_size_35 mediumint(30) NOT NULL,
quantity_size_45 mediumint(30) NOT NULL,
quantity_size_55 mediumint(30) NOT NULL,
quantity_size_65 mediumint(30) NOT NULL,
quantity_size_75 mediumint(30) NOT NULL,
quantity_size_85 mediumint(30) NOT NULL,
quantity_size_95 mediumint(30) NOT NULL,
quantity_size_105 mediumint(30) NOT NULL,
quantity_size_115 mediumint(30) NOT NULL,
quantity_size_125 mediumint(30) NOT NULL
)";
mysql_query($table);
?>
<?
$insert = "INSERT INTO bawtry_stock (
product_id,
title,
wholesale_price,
quantity_c_size_26,
quantity_c_size_28,
quantity_c_size_30,
quantity_c_size_32,
quantity_c_size_33,
quantity_c_size_34,
quantity_c_size_35,
quantity_c_size_355,
quantity_c_size_36,
quantity_c_size_365,
quantity_c_size_37,
quantity_c_size_375,
quantity_c_size_38,
quantity_c_size_385,
quantity_c_size_39,
quantity_c_size_395,
quantity_c_size_40,
quantity_c_size_405,
quantity_c_size_41,
quantity_c_size_415,
quantity_c_size_42,
quantity_c_size_425,
quantity_c_size_43,
quantity_c_size_435,
quantity_c_size_44,
quantity_c_size_445,
quantity_c_size_45,
quantity_c_size_455,
quantity_c_size_46,
quantity_c_size_465,
quantity_c_size_47,
quantity_c_size_475,
quantity_c_size_48,
quantity_c_size_485,
kids_uk_i_3,
kids_uk_i_35,
kids_uk_i_4,
kids_uk_i_45,
kids_uk_i_5,
kids_uk_i_55,
kids_uk_i_6,
kids_uk_i_65,
kids_uk_i_7,
kids_uk_i_75,
kids_uk_i_8,
kids_uk_i_85,
kids_uk_j_9,
kids_uk_j_95,
kids_uk_j_10,
kids_uk_j_105,
kids_uk_j_11,
kids_uk_j_115,
kids_uk_j_12,
kids_uk_j_125,
kids_uk_j_13,
kids_uk_j_135,
kids_uk_j_1,
kids_uk_j_15,
kids_uk_j_2,
kids_uk_j_25,
kids_uk_s_3,
kids_uk_s_35,
kids_uk_s_4,
kids_uk_s_45,
kids_uk_s_5,
kids_uk_s_55,
kids_uk_s_6,
kids_uk_s_65,
kids_uk_s_7,
kids_uk_s_75,
kids_uk_s_8,
kids_uk_s_85,
kids_c_17,
kids_c_18,
kids_c_19,
kids_c_20,
kids_c_21,
kids_c_22,
kids_c_23,
kids_c_24,
kids_c_25,
kids_c_26,
kids_c_27,
kids_c_28,
kids_c_29,
kids_c_30,
kids_c_31,
kids_c_32,
kids_c_33,
kids_c_34,
kids_c_35,
kids_c_36,
kids_c_37,
kids_c_38,
kids_c_39,
kids_c_40,
kids_c_41,
kids_c_42,
kids_c_43,
quantity_size_one,
quantity_size_3,
quantity_size_4,
quantity_size_5,
quantity_size_6,
quantity_size_7,
quantity_size_8,
quantity_size_9,
quantity_size_10,
quantity_size_11,
quantity_size_12,
quantity_size_13,
quantity_size_35,
quantity_size_45,
quantity_size_55,
quantity_size_65,
quantity_size_75,
quantity_size_85,
quantity_size_95,
quantity_size_105,
quantity_size_115,
quantity_size_125 )
SELECT product_id,
title,
wholesale_price,
quantity_c_size_26,
quantity_c_size_28,
quantity_c_size_30,
quantity_c_size_32,
quantity_c_size_33,
quantity_c_size_34,
quantity_c_size_35,
quantity_c_size_355,
quantity_c_size_36,
quantity_c_size_365,
quantity_c_size_37,
quantity_c_size_375,
quantity_c_size_38,
quantity_c_size_385,
quantity_c_size_39,
quantity_c_size_395,
quantity_c_size_40,
quantity_c_size_405,
quantity_c_size_41,
quantity_c_size_415,
quantity_c_size_42,
quantity_c_size_425,
quantity_c_size_43,
quantity_c_size_435,
quantity_c_size_44,
quantity_c_size_445,
quantity_c_size_45,
quantity_c_size_455,
quantity_c_size_46,
quantity_c_size_465,
quantity_c_size_47,
quantity_c_size_475,
quantity_c_size_48,
quantity_c_size_485,
kids_uk_i_3,
kids_uk_i_35,
kids_uk_i_4,
kids_uk_i_45,
kids_uk_i_5,
kids_uk_i_55,
kids_uk_i_6,
kids_uk_i_65,
kids_uk_i_7,
kids_uk_i_75,
kids_uk_i_8,
kids_uk_i_85,
kids_uk_j_9,
kids_uk_j_95,
kids_uk_j_10,
kids_uk_j_105,
kids_uk_j_11,
kids_uk_j_115,
kids_uk_j_12,
kids_uk_j_125,
kids_uk_j_13,
kids_uk_j_135,
kids_uk_j_1,
kids_uk_j_15,
kids_uk_j_2,
kids_uk_j_25,
kids_uk_s_3,
kids_uk_s_35,
kids_uk_s_4,
kids_uk_s_45,
kids_uk_s_5,
kids_uk_s_55,
kids_uk_s_6,
kids_uk_s_65,
kids_uk_s_7,
kids_uk_s_75,
kids_uk_s_8,
kids_uk_s_85,
kids_c_17,
kids_c_18,
kids_c_19,
kids_c_20,
kids_c_21,
kids_c_22,
kids_c_23,
kids_c_24,
kids_c_25,
kids_c_26,
kids_c_27,
kids_c_28,
kids_c_29,
kids_c_30,
kids_c_31,
kids_c_32,
kids_c_33,
kids_c_34,
kids_c_35,
kids_c_36,
kids_c_37,
kids_c_38,
kids_c_39,
kids_c_40,
kids_c_41,
kids_c_42,
kids_c_43,
quantity_size_one,
quantity_size_3,
quantity_size_4,
quantity_size_5,
quantity_size_6,
quantity_size_7,
quantity_size_8,
quantity_size_9,
quantity_size_10,
quantity_size_11,
quantity_size_12,
quantity_size_13,
quantity_size_35,
quantity_size_45,
quantity_size_55,
quantity_size_65,
quantity_size_75,
quantity_size_85,
quantity_size_95,
quantity_size_105,
quantity_size_115,
quantity_size_125
FROM product
ORDER BY product_id ASC";
mysql_query($insert);
感谢您的评论。