----- Original Message ----- From: "Ross" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Tuesday, May 02, 2006 12:00 PM
Subject: [PHP] php mysql problem



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

(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.

If anyone has seen the amazon dvd rental list where you can swap dvd to the top of the list and delete this is what I am trying to achive with php/mysql.

You are mixing up concepts here. An ID is that, an identifier, and it goes with the record from its creation to its deletion. That's what an ID is for (which in most Anglo legal systems is something people is not used to, an anthropological curiosity if you wish). What you are looking for is an Order field (which, of course, you can name as you wish, since order is a reserved SQL word, I just give the concept of it), which is also numerical and that, if you put in your select like Select * from mytalbe order by `order`, id will be used to order records and, if missing, will default to id.

Satyam

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

Reply via email to