Home > php教程 > php手册 > body text

mysql single table multiple updates

WBOY
Release: 2016-08-26 10:12:46
Original
1477 people have browsed it

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>

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template