从select中插入

时间:2013-07-22 22:07:42

标签: select syntax-error insert-into

我有一个我无法理解的小问题。 我希望查询的结果写在现有的表中。

   $ query = "SELECT * FROM actions WHERE 1 = 1";/
w_cliente $ = "";
if ($ customer! = "") {$ w_cliente = "AND customer LIKE '%". $ client. "%'";}
w_cognome $ = "";
if ($ name! = "") {$ w_cognome = "AND name LIKE '%". $ name. "%'";}
w_nome $ = "";
if ($ name! = "") {$ w_nome = "AND name LIKE '%". $ name. "%'";}
$ query. = $ w_tipologia. $ w_cognome. $ w_nome. "ORDER BY id";
$ res = mysql_query ($ query) or die ('Error: Something went wrong');
$ exists = mysql_num_rows ($ res);

此查询可以“打印”查找表。

$ query = "INSERT INTO time SELECT * FROM actions WHERE 1 = 1";/
w_cliente $ = "";
if ($ customer! = "") {$ w_cliente = "AND customer LIKE '%". $ client. "%'";}
w_cognome $ = "";
if ($ name! = "") {$ w_cognome = "AND name LIKE '%". $ name. "%'";}
w_nome $ = "";
if ($ name! = "") {$ w_nome = "AND name LIKE '%". $ name. "%'";}
$ query. = $ w_tipologia. $ w_cognome. $ w_nome. "ORDER BY id";
$ res = mysql_query ($ query) or die ('Error: Something went wrong');
$ exists = mysql_num_rows ($ res);

通过这个我没有看到任何打印在上面,而是在表格中正确地写入数据。 如何在研究中显示视频并同时将数据输入新表? 谢谢。

1 个答案:

答案 0 :(得分:0)

问题是当你连接它们时,你没有在条件之间放置空格。例如,如果设置了$customer,则会得到:

WHERE 1=1AND customer LIKE %$client%

ANDORDER BY之前加一个空格来修复此问题。