从另一个表插入到表中

gpnt7bae  于 2021-08-13  发布在  Java
关注(0)|答案(2)|浏览(347)

好吧,我试图插入到另一个表中,但我得到了这个错误;
wordpress数据库错误: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''lcl_user_agent' (user_agent, hitcount, click_timestap) SELECT visite_useragent,' at line 1] 这是我的密码;

$addagent = "INSERT INTO $wpdb->prefix.'lcl_user_agent' (user_agent, hitcount, click_timestap) SELECT visite_useragent, visite_hitcount, click_timestap FROM $wpdb->prefix.'lcl_visite_agent' .agent_id IN (' . $agent_id . ')";

$wpdb->query($addagent);

我想插入到lcl\u用户\u代理的访问从访问\u用户代理然后我得到访问块与 $agent_id 从表单

jei2mxaa

jei2mxaa1#

看来你最后搞砸了。应填写以下表格:

INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;

所以也许这就是你想要的?

$addagent = '
 INSERT INTO 
        '.$wpdb->prefix.'lcl_user_agent
        (user_agent, hitcount, click_timestap) 
    SELECT 
        visite_useragent, visite_hitcount, click_timestap 
    FROM 
        '.$wpdb->prefix.'lcl_visite_agent
    WHERE
        agent_id IN (' . $agent_id . ')
 ';
pu82cl6c

pu82cl6c2#

试一试:
$addagent = "INSERT INTO " . $wpdb->prefix . 'lcl_user_agent' . " (user_agent, hitcount, click_timestap) SELECT visite_useragent, visite_hitcount, click_timestap FROM " . $wpdb->prefix.'lcl_visite_agent' . " where agent_id IN (' . $agent_id . ')"; $wpdb->query($addagent); 我从来没有在双引号字符串中嵌入->的运气。只是更清楚地将字符串串联在一起。另外,在这种情况下,除非你有多个 $agent_id 价值观,你可以考虑 where agent_id = $agent_id 而不是在中使用。

相关问题