PDA

View Full Version : process for creating a new id for a new product "post"


sweeps78
10-05-2011, 06:03 PM
It's been a long time since I did some serious php and database work so bear with me:)

I have a product I'm working on that consists of a thread/post architecture. What I'm working on now is trying to figure out how to create a new ID for when inserting new records in the DB. Normally, I would think that I would just do a count on the records of that table and add 1 to create a new unique ID, but going through some other products people have created I see things like "$cleanfileid = $vbulletin->input->clean_gpc('r', 'id', TYPE_UINT);" being used a lot so I was curious if vBulletin already has a prebuilt function to generate new IDs.

kh99
10-05-2011, 06:19 PM
I think the way it works in vb is that there's a database column defined as auto_increment so whenever you add a record, that field is automatically set to the next value. Then if you need the new id in your code you can call $db->insert_id() to get the value from the last insert.