比如数据库中有若干条数据,想将每一条数据中的二个字段相加得到的和插入到另一字段中:
cca ccb ccd id
45 66 0 1
67 36 0 2
86 24 0 5
76 84 0 8
6 55 0 12
……
单条计算如下:
<?phprequire_once("header.php");$q="select * from member where id='5'";$r=$obj_db->simplequery($q);$a=$obj_db->fetchRow($r,DB_FETCHMODE_ASSOC);$ccd=$a[cca]+$a[ccb];$obj_db->simplequery("update member set ccd='$ccd' where id='5'");?>
$obj_db->simplequery("update member set ccd=cca+ccb where id='5'");
$obj_db->simplequery("update member set ccd=cca+ccb where id='5'");
$obj_db->simplequery("update member set ccd=cca+ccb");
$obj_db->simplequery("update member set ccd=cca+ccb");
这个才是楼主要求的,全表一次搞定
这就是标准的sql啊 跟php就没关系 . grammer: update tablename set cloum='' where ..
$obj_db->simplequery("update member set ccd=cca+ccb");
十分感谢!再继续请教一下:
如果要判断cca+ccb>110的才计算,怎么这样写不对啊:
$obj_db->simplequery("update member set ccd=cca+ccb where sum(cca+ccb)>110");
请帮忙纠正一下代码,谢谢!
update member set ccd=cca+ccb where cca+ccb>110
update member set ccd=cca+ccb where cca+ccb>110
谢谢