update table1 set listid=listid-1,listid='5' where listid>2;
解决方案 »
- 一个小问题 用serialize()函数之后,返回的string保存在内存吗?
- 关于MYSQL存储过程
- php在服务器上运行出现FastCGI
- SESSION不变是怎么回事
- 技術請教;可行就給分,決不食言
- 关于自动增加ID记录的问题,郁闷!
- 友情奉献
- 关于php mail函数的用法
- 使用 phpMyAdmin 来导入数据表,应该如何操作?
- 编写一个程序,能够阻止其他用户非法“拷贝”,“删除”,“新建”,“阅读”文件或目录。对以上4个操作,操作之前必需输入密码才能进行。例如用户双击某个文件夹或文件时
- 接收表单传送数据的问题
- ORA-06401: NETCMN: invalid driver designator
select * from table1 order by listid;
,listid='5' 是什么意思?如何实现了b的值变为最大?
另外,既然第一句已经把temp改变成了max,那岂不两个listid都等于max了?应该
update table1 set listid='$max+1' where listid='$temp'
update table1 set listid=listid-1 where listid>'$temp' and listid<($max+2);
这样吧?
本人认为应该这样写:
//先将其它的依次减一
update table1 set listid=listid-1 where listid>'".$temp."' and listid<($max+1);
//然后再将该记录置为最大
update table1 set listid='".$max."' where listid='".$temp."' 其实$max,$temp值是先要知道的你那样写,岂不是最大值比原来的大了一??你多试试吧,肯定行的,要不你把数据表结构和数据给我一份,我给你调调看看
我那样写没有大一啊。因为第二个语句已经listid=listid-1了嘛。之所以我想在尽可能少的语句里面实现,是为了高效的利用这个自定义的小函数。因为多处用到。而那个最大值除了此函数以外没什么用,所以在该函数里面读出即可。而不是传递过来的。
update table1 set listid='".$max."' where id='".$temp."'
这样就可以了,我自己创建了个表,测试通过。
$sql="select max(listid) as max_listid from test ;";
$result1 = $mysql_server->send_result_sql($sql,0);
$listrow=mysql_fetch_array($result1);
$max_listid=$listrow[max_listid];
echo $max_listid;
$temp=2;//先将其它的依次减一
$sql="update test set listid=listid-1 where listid>'".$temp."' and listid<($max_listid+1);";
$result1 = $mysql_server->send_result_sql($sql,0);
//然后再将该记录置为最大
$sql="update test set listid='".$max_listid."' where id='".$temp."' ";
$result1 = $mysql_server->send_result_sql($sql,0);这是我亲自测试的,没问题,可以实现你说的功能
(数据库连接你们的即可,我是用的类,你看看就明白了)
你自己将它整理成函数,在需要的地方调用即可。
用两个sql不就实现了嘛!!
update table1 set listid=listid-1 //这句是让所有的记录都加1
update table1 set listid=5 where name=b //这句是让b的listid变成5
多简单!
你的记录如果有10000条,这两个语句仍然适用!
id name listid listid(全部减一) listid(b->5) listid(实际想实现)
1 a 1 0 0 1
2 b 2 1 5 5
4 c 3 2 2 2
8 d 4 3 3 3
9 md 5 4 4 4
我的其实也是两条sql语句。