|
Posted by Richard Lynch on 04/30/05 00:38
On Fri, April 29, 2005 2:14 pm, Ross Hulford said:
> I have a table with 15 columns or so that has been inherited from an older
> db and am trying to insert an auto increment column (in mysql) without
> having to number it manually. This is fine when I add new colums via a
> form
> but the old entries have a null value
$new_id = 1;
do {
$query = "select SOMETHING_UNIQUE from whatever where NEW_ID is NULL
LIMIT 1";
$results = mysql_query($query);
$something_unique = mysql_result($results, 0, 0);
$query = "update whatever set NEW_ID = $new_id where SOMETHING_UNIQUE =
$something_unique";
mysql_query($query);
} while (mysql_num_rows($results));
> Alternatively It has been converted from Excel soif anyone knows how to do
> it that way that would help.I never use Excel so have no clue about it.
In excel, you can just put '1' in the first row, and then move down a row,
and type the following sequence:
=[up_arrow]+1
and hit enter
At that point, you should be seeing a '2' in the second row.
You can copy that cell, highlight rows 3 through N, and use "Paste"
All your rows are now numbered, 1 to N.
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|