最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - update multiple rows in mysqli table base on two values

programmeradmin0浏览0评论

I know this is an old question that is repeated here a lot. but I couldn't find an answer that works, and my code is really bad. How can i update multiple rows in one query when i have to use two keys to run through in my query. I saw a lot of answers. But no one worked for me.

my table:

id| entry  | meta_key | meta_value
1 |    1   |     2    |   input1
2 |    1   |     3    |   input2
3 |    1   |     4    |   input3
4 |    2   |     5    |   input4

i'm updating the table using the entry as an id. but the code is repetitive. the only pice of data that is fixed is the meta_key. and will not change.

$result = $wpdb->query("UPDATE `table_name` SET `meta_value`= '".$meta_value1."' WHERE `entry` = '".$entry."'  AND `meta_key` = 2");
$result = $wpdb->query("UPDATE `table_name` SET `meta_value`= '".$meta_value2."' WHERE `entry` = '".$entry."'  AND `meta_key` = 3");

how can i make this code good.

P.S my code works

发布评论

评论列表(0)

  1. 暂无评论