Home >php教程 >php手册 >简化SQL语句一例

简化SQL语句一例

WBOY
WBOYOriginal
2016-06-13 10:05:231379browse

举个例子,设表名为bbs 回复数的字段为renum 变量名$renum 记录序号字段为id 变量名$id
当我们在论坛回贴时会要改写主贴的回复数,传统的方法要用到到两句SQL语句:
//取出原值
$query1="select renum bbs where id = '$id'";
……
$renum ;
//写回数据库
$query2="update bbs set renum = '$renum' where id = '$id'";
简化后如下:
$query="update bbs set renum = renum 1 where id = '$id'";
一句搞定!

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