更新当前行的列

时间:2019-08-19 15:25:08

标签: php sql wordpress

我正在遍历联系人,提取特定数据,然后想要更新当前行上的特定列。我怎样才能做到这一点?

该行位于最底部,我只想将其从0更改为1。

    require('../mailin.php');
    $mailin = new Mailin("https://api.sendinblue.com/v2.0","Your access key");


  $customer_data = $wpdb->get_results("SELECT * FROM imp_customer_log WHERE updated_in_sib = '0'");
    foreach( $customer_data as $customer ) {

        $customer_id = $customer[0];
    $customer_event = $customer[1];
    $customer_data = $customer[2];
    $customer_sib = $customer[3];

        $user = get_user_by( 'id', $customer_id );
        $user_email = $user->user_email;

        $data = array(
            "email" => $user_email,
            "attributes" => array(
                $customer_event => $customer_data,
            ),
        );

        var_dump($mailin->create_update_user($data));
        // Change updated_in_sib to 1 for current row

  }

2 个答案:

答案 0 :(得分:2)

我认为这是一个WordPress。您可以在wpdb中使用更新功能,如下所示。

$wpdb->update('imp_customer_log', ['customer_sib' => 1], ['id' => $customer_id]);

您可以在文档中检查它。 https://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

用于php(不是wordpress)

$sql = "UPDATE imp_customer_log SET customer_sib=1 WHERE id=" . $customer_id;
$connection->query($sql);

答案 1 :(得分:0)

我认为您正在使用Wordpress。看看这些wordpress文档进行更新,就像在您的问题中使用get_results()一样。

https://developer.wordpress.org/reference/classes/wpdb/update/

$wpdb->update( string $table, array $data, array $where, array|string $format = null, array|string $where_format = null )