用一个for 循环,然后:
$sql=" update  ...."

解决方案 »

  1.   

    把数值放到一个array之后,
    用sort函数排序
      

  2.   

    为什么要那样呢?在用的时候直接$sql="......order by asc"不就出来顺序了么
      

  3.   

    froole: 用数组排好后,数据库里的表怎么更新呢? 如果数据库里有很多条记录(例如 100万)呢?
      

  4.   

    显然,一定要用 SQL 语句、包括可能用存贮过程来更新表的。
      

  5.   


    汗死了,你说的是用PHP语言实现。数据库的话用order by语法,
    PHP直接提取结果就可以了。
      

  6.   

    loveapple: 没搞明白问题的本意不要胡扯!
      

  7.   

    用这样的语句,把生成结果insert到一个空表里即可
    select a.id, a.a2, count(a.id) as ccc
    from t3 a, t3 b
    where a.a2>=b.a2
    group by a.id 
    order by a.a2测试表及数据:CREATE TABLE `t3` (
      `id` int(11) unsigned NOT NULL auto_increment,
      `a1` int(11) unsigned NOT NULL,
      `a2` varchar(50) NOT NULL,
      `a3` varchar(50) NOT NULL,
      `a4` datetime NOT NULL,
      `a5` text,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;/*Data for the table `t3` */insert into `t3` (`id`,`a1`,`a2`,`a3`,`a4`,`a5`) values (1,1,'444','1','0000-00-00 00:00:00',NULL),(2,1,'999','1','0000-00-00 00:00:00',NULL),(3,1,'111','1','0000-00-00 00:00:00',NULL),(4,2,'333','1','0000-00-00 00:00:00',NULL),(5,2,'888','1','0000-00-00 00:00:00',NULL),(6,3,'777','1','0000-00-00 00:00:00',NULL),(7,1,'222','1','0000-00-00 00:00:00',NULL),(8,2,'555','1','0000-00-00 00:00:00',NULL),(9,3,'666','1','0000-00-00 00:00:00',NULL);
      

  8.   


    lz要问的是那种情况的排序?回答你得你够写一篇论文了。
    1.大多数web系统的实际运用中,从数据库提取数据的问题
      从PHP程序员的角度,就是order by的问题。具体再怎么高效,那就是数据库管理的问题了,超出PHP的范围。
    2.从数据库提取无序数据之后,进行排序
      是给学生讲的排序算法问题吗?还是要用PHP写个RDB的功能?数据量大了,想要高效处理,哪一个深究起来都够写点内容了。
    lz的提问可真不简单呐。
      

  9.   

    100万条数据又不多
    for就够了,做了一个从多少条到多少条处理,然后跳转到下一个多少条到多少条,这样脚本不会超时。
    反正是整理数据库,又不要考虑多高的效率
      

  10.   

    楼主是要用PHP来实现,如果是我,会选择删除那个字段,重新建个同名自增字段
      

  11.   

    或者新建个自增字段,update table set  filed1=field2
      

  12.   

    mySQL数据库,一个表,想把某字段的值按照顺序更新为1,2,3,4,5,6,7,……,用 PHP 语言实现,怎么做最快速和高效?用个循环for就足够了,$total="select count(*) 表";计算有多少条数据,在用FOR循环修改下好了:如:$total="select count(*) 表";
    for($i=1;$i<=$total;$i++){
    $sql=" update  .... where id='$i'";
    mysql_query($sql);
    }
    这样也可以实现的
      

  13.   


    create table tb1(
    id int(10) auto_increment primary key,
    paixu int(10) not null default 0,
    other_value text
    );
    insert into tb1(id,paixu,other_value) values (3,0,'aaa');
    insert into tb1(id,paixu,other_value) values (51,0,'bbb');
    insert into tb1(id,paixu,other_value) values (225,0,'ccc');
    insert into tb1(id,paixu,other_value) values (12,0,'aaa');
    insert into tb1(id,paixu,other_value) values (21,0,'bbb');
    insert into tb1(id,paixu,other_value) values (85,0,'ccc');
    create table tb2(
    id int(10) auto_increment primary key,
    tb1_id int(10) not null default 0,
    paixu int(10) not null default 0,
    other_value text
    );
    insert into tb2 (tb1_id,paixu,other_value) select * from tb1;
    update tb2 set paixu=id;
    alter table tb2 drop column id;
    alter table tb2 change tb1_id id int(10) not null primary key;
    drop table tb1;
    rename table tb2 to tb1;
    mysql> select * from tb1;
    +-----+-------+-------------+
    | id  | paixu | other_value |
    +-----+-------+-------------+
    |   3 |     1 | aaa         |
    |  51 |     2 | bbb         |
    | 225 |     3 | ccc         |
    |  12 |     4 | aaa         |
    |  21 |     5 | bbb         |
    |  85 |     6 | ccc         |
    +-----+-------+-------------+
    6 rows in set (0.00 sec)
      

  14.   

    谢谢 vvkl,但感觉用临时表来实现挺别扭的。
    也不知道大量记录,如上百万甚至上千万条的情况下速度如何。
      

  15.   

    你只要定义一个变量给它初始化
    例如
    $s_i=0;

    $s_i++;就行
      

  16.   

    问题没说清,不明白要干什么,
    mySQL数据库,一个表,想把某字段的值按照顺序更新为1,2,3,4,5,6,7更新的时候也要先有个顺序排列吧,是主键递增的顺序更新,还是主键递减更新?