The 'problem' here is the logic of sql databases.

you have one id and one 'username' and they belong to eachother.
id 1 -> user 1
id n -> user n

meaning if you delete user 23, only id 23 is affected. If you want the
userid 'resorted' you will have to issue a few commands (which also would
destroy the logic of having the id column at all)

alter table mytable drop idcolumn;
alter table mytable add idcolumn unsigned int not null auto_increment
[primary key];

add primary key if it is the primary key.

I would rather suggest you dropped the 001 002 003 column, and used php to
keep count.

example

user001
user002
user0..
user075 (lets say you have 65 users total and that somewhere in 30-50 you
have been deleting)

$res = mysql_query("select username from mytable");
$num = mysql_num_rows($res); // this would give 65

$i = 1;
while($row = mysql_fetch_row($res)) {
        echo "user id $i - username ".$row[0]; $i++;
}

this would print a list from 001 - 065 with every username in it.

Mats Remman
PHP Developer/Mysql DBA
Coretrek, Norway
+47 51978597 / +47 916 23566



> -----Original Message-----
> From: Wilmar Pérez [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 04, 2001 10:50 PM
> To: PHP List
> Subject: [PHP-DB] Authomatic Sorting
>
>
> Hello guys
>
> I have the following two problems:
>
> I've got a table with an autoincrement field which is the registry's ID,
> everything goes well until I delete any registry.  MySQL doesn't re-sorts
> the information.  That is, I have the following:
>
> 001  user1
> 002  user2
> 003  user3
>
> If I delete user2, I would like to have something as shown next:
>
> 001  user1
> 002  user3
>
> But instead I end up with the following:
>
> 001  user1
> 003  user3
>
> Any idea or comment?
> -----------------------------------------------
>                 Wilmar Pérez
>      IT Manager - Central Library
>          University of Antioquia
>            Medellín - Colombia
>           tel: ++57(4)2105145
> -----------------------------------------------
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to