Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How To Populate A Field In A MySQL With uniqueid()?

    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.
    Last edited by cypherinfo; 06-23-2010 at 04:03 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •