Re: Pragmatically changing a "Record Number"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 10:27 AM +1000 9/3/07, Chris wrote:
tedd wrote:
At 6:14 PM -0400 9/2/07, brian wrote:
tedd wrote:
Hi to the original poster:

Snip -- a lot of discussion

Use the following code at your own peril.

$dbQuery = "ALTER TABLE $dbtable ";
$dbQuery .= "DROP id, ";
$dbQuery .= "ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,";
$dbQuery .= "AUTO_INCREMENT = 1";
$result = mysql_query($dbQuery) or die("Could not renumber dB $dbQuery" . mysql_error());

The reason for not wanting to care about the auto_increment id is that it is something that the database uses and really should not be changed. If you want to have a sequential record number, then add that field and alter it as you will, but leave the internal workings of database alone.

However, if you wish not to understand how all that works, then use the code above -- it will renumber your auto_increment id leaving no gaps.

-snip-


How is that contrary to what I said?

You are actually changing the id's in the database.

Brian's example is making up an id to display (much like the excel row numbers) rather than actually changing the id in the database.

Please read what I said above, If you do, then you will see that I advised against altering the index and recommend setting up another field for displaying a record sequence.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux