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

简化SQL语句一例

WBOY
Release: 2016-06-13 10:05:23
Original
1263 people have browsed it

举个例子,设表名为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'";
一句搞定!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!