Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 数据库

PHP 数据库

WBOY
WBOYOriginal
2016-06-23 14:00:01859Durchsuche

数组:Array ( [0] => Array ( [id] => 42 ) [1] => Array ( [id] => 49 ) [2] => Array ( [id] => 50 ) [3] => Array ( [id] => 51 ) [4] => Array ( [id] => 52 ) ) ?,这里为数据表里的id字段,怎样根据这些id,修改每一个id对应的另一个字段count?第一个id的count加1,第二个id对应的加2,第三个加3.。。。。这样循环下去


回复讨论(解决方案)

$arr = array ( 0 => array ( 'id' => 42 ) ,1 => array ( 'id' => 49 ), 2 => array ( 'id' => 50 ), 3 => array ( 'id' => 51 ), 4 => array ( 'id' => 52 ) );foreach ($arr as $key => $value) {	$sql = "update tableName set count = count + ".($key+1)." where id = ".$value['id'];	mysql_query($sql);}

$ar = array ( 0 => array ( 'id' => 42 ) ,1 => array ( 'id' => 49 ), 2 => array ( 'id' => 50 ), 3 => array ( 'id' => 51 ), 4 => array ( 'id' => 52 ) );$s = join(',', array_map('current', $ar));$sql = "update tbl_name set count=count+find_inset(id,'$s')";mysql_query($sql);

版主大大的代码 看不懂!

版主好强!不过好像是find_in_set

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn