简化SQL语句一例

来源:互联网 发布:微星电池校准软件 编辑:程序博客网 时间:2024/04/29 08:30
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
举个例子,设表名为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'";
一句搞定!
转自:动态网制作指南 www.knowsky.com<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击