Home > Backend Development > PHP Tutorial > ,利用数组更新mysql数据库数据的方法

,利用数组更新mysql数据库数据的方法

WBOY
Release: 2016-06-13 10:09:09
Original
1266 people have browsed it

求助,利用数组更新mysql数据库数据的方法
我想要实现,根据数组的键值和值来实现对数据的更改。
例如:$arr[13]='张三';$arr[14]='李四'
  根据$arr这个数组的键值和值,去实现更改数据库中id=3和id=4的数据。键值是年龄,值是名字。
呼唤高手帮忙。

------解决方案--------------------

PHP code
//附加 id,变形为$ar = array(  3 => array(13 => '张三'),  4 => array(14 => '李四'),);foreach($ar as $id=>$v) {  list($name, $aeg) = each($v);  $sql = "update tbl_name set aeg=$aeg, name='$name' where id=$id";  //执行数据库操作}<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template