Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从不同的表数据更新表行无效_Php_Mysql_Database_Wordpress - Fatal编程技术网

Php 从不同的表数据更新表行无效

Php 从不同的表数据更新表行无效,php,mysql,database,wordpress,Php,Mysql,Database,Wordpress,我的数据库中有两个表。一个名为wp\u tickets,另一个名为wp\u tickets\u 如果wp\u tickets表中的wp\u tickets\u重新生成的wp\u tickets表中的lotkets\u id匹配,我将尝试更新wp\u tickets\u重新生成的表中的一些数据,因此我最终得到了一个新表,该表为该产品下的每个订单生成了不同的ticket\u编号 到目前为止,我的代码出现了一个错误: WordPress database error You have an erro

我的数据库中有两个表。一个名为
wp\u tickets
,另一个名为
wp\u tickets\u

如果
wp\u tickets
表中的
wp\u tickets\u重新生成的
wp\u tickets
表中的
lotkets\u id
匹配,我将尝试更新
wp\u tickets\u重新生成的
表中的一些数据,因此我最终得到了一个新表,该表为该产品下的每个订单生成了不同的ticket\u编号

到目前为止,我的代码出现了一个错误:

 WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM wp_tickets
        WHERE lottery_id = wp_tickets.lottery_id' at line 6 for query UPDATE wp_tickets_regenerated
有人能帮忙吗

wp\u票务表

+---------+-----------+-----------+---------------+----------+------------+
| user_id | full_name | answer_id | ticket_number | order_id | lottery_id |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 3             | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 5             | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 10            | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+
wp\u票据重新生成

   +---------+-----------+-----------+---------------+----------+------------+
    | user_id | full_name | answer_id | ticket_number | order_id | lottery_id |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 1             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 2             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 3             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+
到目前为止,我得到的是:

 $wpdb->query(
       'UPDATE wp_tickets_regenerated
        SET user_id = wp_tickets.user_id,
            full_name = wp_tickets.full_name,
            answer_id = wp_tickets.answer_id,
            order_id = wp_tickets.order_id
        FROM wp_tickets
        WHERE lottery_id = wp_tickets.lottery_id'
  );

可能您需要一个内部连接进行更新

    UPDATE wp_tickets_regenerated a 
    INNER JOIN wp_tickets b a.lottery_id = b.lottery_id
    SET a.user_id = b.user_id,
        a.full_name = b.full_name,
        a.answer_id = b.answer_id,
        a.order_id = b.order_id

(不使用更新中的from…)

您需要一个内部联接表
wp\u tickets
进行更新

    UPDATE wp_tickets_regenerated a 
    INNER JOIN wp_tickets b a.lottery_id = b.lottery_id
    SET a.user_id = b.user_id,
        a.full_name = b.full_name,
        a.answer_id = b.answer_id,
        a.order_id = b.order_id
试试这个

UPDATE wp_tickets_regenerated
INNER JOIN wp_tickets ON wp_tickets_regenerated.lottery_id = wp_tickets.lottery_id
SET wp_tickets_regenerated.user_id = wp_tickets .user_id,
    wp_tickets_regenerated.full_name = wp_tickets .full_name,
    wp_tickets_regenerated.answer_id = wp_tickets .answer_id,
    wp_tickets_regenerated.order_id = wp_tickets .order_id
WHERE wp_tickets_regenerated.lottery_id = wp_tickets.lottery_id'
希望这对您有所帮助