The task is to number lines in the database. Those. I would do it like this:

$lines=mysql_get_lines("SELECT `id` FROM 'table' WHERE `parent`=12"); // И потом на PHP сделал бы цикл: $i=1; foreach($lines as $line){ mysql_query("UPDATE `table` SET `order`=$i WHERE `id`=".$line['id']); $i++; } 

Is it possible to do a similar operation with a single query to the database?

    1 answer 1

    Not exactly one, after all two, but yes, it is possible through a user variable:

     set @i := -1; update tablename set order = (@i := @i+1 ) where parent=12 order by id;