View Full Version : Getting the id of a result before it's posted?
DrewM
05-13-2006, 11:54 PM
I have a tutorial system set up. I have just added a feature that allows images for the tutorial to be uploaded to data base. It saves them with the tutorial id so it can repeat the image code for the tutorials using a where cause with tutorial ids. But I can't do this if the tutorial id is not posted yet. Is it possible to get the id before it's posted is my basic question.
:banana:
filburt1
05-14-2006, 12:09 AM
Lock the table, find out the first available ID, insert all your stuff related to the ID, and then unlock the table. The locking is to avoid concurrent modifications and hence duplicate IDs. You won't encounter the problem unless you are making a lot of queries each second.
akanevsky
05-14-2006, 12:12 AM
I suggest doing this the way vBulletin handles newpost attachments: each new post has a posthash, which serves as the temporary ID.
DrewM
05-14-2006, 01:09 PM
I suggest doing this the way vBulletin handles newpost attachments: each new post has a posthash, which serves as the temporary ID.
How could I do this? Would you just have it do random numbers like session?
akanevsky
05-14-2006, 01:12 PM
Yes. You generate a hash when you first access the new post page, then you pass the hash on via $_POST data. When you insert data into other tables, insert it without specifying id, but with specifying the hash. Then, when you actually save the whole post, update the entries by removing the hash and inserting the real id.
DrewM
05-14-2006, 01:14 PM
Yes. You generate a hash when you first access the new post page, then you pass the hash on via $_POST data. When you insert data into other tables, insert it without specifying id, but with specifying the hash. Then, when you actually save the whole post, update the entries by removing the hash and inserting the real id.
thanks
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.