List:General Discussion« Previous MessageNext Message »
From:Peter Brawley Date:August 27 2005 8:07pm
Subject:Re: newbee question
View as plain text  
Ross

/>Using mysql with php I have a database that has a unique value
 >for the user id. when people get delete off the list I want the unique
 >numbers to compact down so./

Generally it's a really bad idea to edit primary keys. If you absolutely 
must compact the key values, you can do it by altering the table to drop 
the primary key, then run something like this,
  SET @i=0;
  UPDATE parent2 SET id=(@i:=@i+1);
then alter the table again to re-establish the primary key.

/>If this is not possible how can I find the first entry in
 >the database and last entry with php/mysql?
/
To find the lowest id value
  SELECT id FROM tablename ORDER BY id ASC LIMIT 1;
and to find the highest
  SELECT id FROM tablename ORDER BY id DEC LIMIT 1;

PB
http://www/artfulsoftware.com

-----

ross@stripped wrote:

>Using mysql with php I have a database that has a unique value for the user id. when
> people get delete off the list I want the unique numbers to compact down so.
>
>user id 1
>user id 4
>user id 5
>user id 7
>user id 9
>user id 10
>
>becomes 
>
>user id 1
>user id 2
>user id 3
>user id 4
>user id 5
>user id 6
>
>If this is not possible how can I find the first entry in the database and last entry
> with php/mysql?
>
>R.
>  
>
>------------------------------------------------------------------------
>
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.344 / Virus Database: 267.10.16/83 - Release Date: 8/26/2005
>  
>

Attachment: [text/html]
No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.16/83 - Release Date: 8/26/2005
Thread
newbee questionross27 Aug
  • Re: newbee questionleegold27 Aug
    • Re: newbee questionStijn Verholen27 Aug
  • Re: newbee questionPeter Brawley27 Aug
  • Re: newbee questionPeter Brawley27 Aug