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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745075562a4609813.html

相关推荐

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

    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

    14小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信