Forum Moderators: coopster

Message Too Old, No Replies

php numbers

         

adamnichols45

6:47 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi guys just would like to know a way of generating a unique number everytime i want to input a new listing into a database please.

jatar_k

6:54 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you just using it as some sort of unique id to identify individual records?

normally I amke the id field an int that is AUTO INCREMENT, then when I insert it takes care of itself and the int is always unique.

ergophobe

6:56 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



When you create the DB table, make that field auto-incrementing and it's all taken care of.

adamnichols45

6:59 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes i would normally but im using csv as well and it does not like the auto increment it dont work properly with auto increment on so i wont another way of doing this guys.

adamnichols45

7:46 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$dt=date( "YmdHis"); would this be ok to generate a unique id?

jatar_k

8:06 pm on Mar 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it should still work properly with csv

I usually do the same, one extra column in my db that is not in my csv called table_id or something. I then do my inserts like so

insert into tablename values ('',$csvcol1,$csvcol2,$csvcol3,$csvcol4);

where the quotes at the beginning are for the auto increment field.

My guess would be that something else is going wrong if the auto increment isn't working.

adamnichols45

10:52 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well i have tryed loads of things and it has not worked!

how about having to id fields on with autoincrement and one with out to use with csv. BUT i then need to select both id fields and output that to the webbrowser how would it be best to do this?

grandpa

11:07 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The auto increment will work. I'm going to guess that you are trying to populate the auto increment field, and that won't work. The database will handle the incrementing for you.

Look again at jatar_k's example. He's not populating that field with anything.
insert into tablename values (' ',$csvcol1,$csvcol2,$csvcol3,$csvcol4);

Most of my tables have the first field defined with the name of 'recid' and set as Primary with auto increment on. When I add a record I never include the field 'recid' in my statement. The field 'recid' becomes useful when I want to update or delete a row in my table.