Reply to Re: [PHP] inserting an auto incemented column in table already created

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация