Home >php教程 >php手册 >mysql single table multiple updates

mysql single table multiple updates

WBOY
WBOYOriginal
2016-08-26 10:12:461508browse

mysql single table multiple updates php single table multiple updates
//single table multiple updates: test sql: success (returns the number of updates successfully, returns 0 on failure)
// $d->execute("UPDATE ez_shop_goods SET inventory = CASE id WHEN 3 THEN 1 WHEN 4 THEN 1 WHEN 5 THEN 100 END WHERE id IN (3,4,5)");

The meaning of this sql is to update the inventory field. If id=3, the value of display_order is 1, if id=4, the value of display_order is 1, and if id=5, the value of display_order is 100.

Convert to tp version:
$goods_ids is the id array of the table to be updated
$value3 is an array of values ​​of the inventory field corresponding to the id
An id corresponds to the value of an inventory field.            $sql = "UPDATE ez_shop_goods SET inventory = CASE id "; foreach ($value3 as $id => $ordinal) { <br>                  $sql .= ' WHEN '.$ordinal['id'].' THEN '.$ordinal['inventory']; <br>                } <br> $ SQL. = "End WHERE ID in ($ IDs)";                                // dump($sql);exit;<br>                $res = $d->execute($sql);<br>                     if($res == 0){<br>                    $errcode = -1;<br> return false;                  }<br> <br><br><br>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn