<?php mysql_query("alter table `categories` add column `order` varchar(3) NOT NULL default ''") or die(mysql_error()); ?> PHP: how can i insert a value in "order" based on id? id name order 1 something 1 3 something 2 5 something 3
I doubt someone can construct query so solve this completely in SQL. Anyway you should use application logic.
are you saying it can't be done? the problem at hand,it doesn't really matter.i can enter all 0 and it would be fine. just seeing if it can be done.
I have time to think a little bit more about this task Solution is the following: - create one more table having the same structure as 'categories', but 'order' field should be autoincrement - copy content of current table by the sql below. it creates correct order assignment insert into `tmp_categories` (id, name) select id, name from `categories` order by id - delete content of categories table - copy content from tmp_categories to categories