Hi All
If antone can please help
I have my table set with a field set as autonumber witch works perfect
What i would like to do is get the next auto number before it is added on the add page, IE list say i have 125 records in my database i would like to add a php snipit on the list page that show the next autonumber IE 126, this would not change no matter what information is listed
Thank you all
Ricky
One of the issues here is the add actually doesn't take place until all the validations have been successful. This is a multi-user environment, there can be in theory many other users also wanting to add records to this table. The next user that has completed validations is in the race to get the next available autonumber. We don't want to break that, even if you think there can only be one user now. Its actually quite difficult to stop other users. The completion of the add transaction could take a half-hour, while the user has a coffee. Lots of opportunity for other users to race ahead.
One way to do what you are asking is to reserve a number at the start of the transaction. If the add never completes, then the number is discarded. You can keep a state flag in the record, pending, complete, or discard, or just delete the record on discard if the transaction is abandoned.
So you start the transaction off, do an insert/add with state "pending" to reserve the record (no other data needed, but a timestamp would be handy), grab the autonumber out of that record using an SQL/PHP function. Display it and do what you need to do while the transaction is being prepared. Then do an "update" of that same record with the clean data when the "add" successfully completes, change the state to "complete". If the add is abandoned, then either change the state to "discard" or delete the record (or while not as tidy, just leave it as pending). If the system times-out or fails in the midst of all this, then the unused reserved record just get left as pending. They can be cleaned up when the system is offline.