Ross schrieb:
Just say I have a db

CREATE TABLE `mytable` (
  `id` int(4) NOT NULL auto_increment,
`fileName` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;


when I add items they go id 1,2,3 etc. Whn I delete them gaps appear. 1, 3, 7. I need to know

(a) when items are removed how can I sort the database to all the gaps are take out 1, 3, 7 becomes 1,2,3

Why do you auto_increment them then?

Normally it's very wrong to set back autoincremented values because you don't have any reference anymore.

So if ID X is causing an error it could be Article X or Article Y or article Z. You don't know because the database is shifting it around. Add a second field called "sort" or something similiar and let it sort on that.
Or give it Article Numbers or whatever.


(b) allow the ids to be changed so the items can change position in the list. If I change id 3 to id 1 then everything else shifts down.
update id = id +1 WHERE id > X

Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to