...

View Full Version : How To Populate A Field In A MySQL With uniqueid()?



cypherinfo
06-23-2010, 03:57 PM
How To Populate A Field In A MySQL With uniqueid()?

Postby ticonzero Wed Jun 23, 2010 3:22 pm
Hello, I'm a newbye here and about PHP; be patient please :-)

I have a mySQL table with 15000 rows; I need to populate a field of it (varchar(15)) - to be used in a way similar to a primary key - with the uniqid() PHP function.

The algorithm is:

1 - positioning to the first row (record);
2 - generating a value with the uniqid() function;
3 - updating with it an empty field of that record;

All of those three steps till to the end of of the table (all of the records).

What is the PHP code to do all of that please?

Thank you.



Cypherinfo.

mlseim
06-23-2010, 08:43 PM
So, at this point, you DO NOT have a column with an auto-increment ID?

All tables should have a column with a unique auto-increment ID in it.
Usually, it starts at 1 and increments. If you add rows, it increments
to the next one. If you delete rows, it never duplicates that ID again.
That's usually how it works, although you can force it to fill-in missing
numbers.

=================

To create a new column with an ID, starting at 100000 ...

You have to enter the name of your table and the name of the column ...

ALTER TABLE `tablename` ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT=100000 PRIMARY KEY ;

You can run that query manually, using your MySQL admin panel.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum