Wrox Programmer Forums
|
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2005, 10:16 AM
Registered User
 
Join Date: Apr 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to preston2003
Default sequence number for online receipt

can anyone help me with a code to generate sequence number? i have a online receipt form and i want to generate a sequence receipt number everytime someone submits a receipt.

thanks

 
Old April 25th, 2005, 02:02 AM
Registered User
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you'll be using MySQL as a way to store the receipt, you can simply define the field for your receipt number as a numeric/integer type (of an appropriate size), and set it to auto-increment. It will do the work for you, generating a new number as soon as you create a record. I'm pretty sure the field has to be keyed (indexed), but not sure if it has to be a primary key. (Mind's getting hazy - that's what I get for using a table editor to do my work) That's how I'd recommend doing it, because you let MySQL handle the overhead.

www.MySQL.com (and several mirror sites) have the manuals online, so you can see how to use the AUTO_INCREMENT attribute in your declaration.

If you're not using MySQL to store the info (or if you need the number long before you create a record for it) you'll have to keep the last used number (written to a text file, kept in a one-record, one-field table, whatever) so you can look it up when you need it, and add 1 to it. You then store that new number in the same place, so if somebody else asks for one afterwards, they'll generate the next number after yours.

Unfortunately with that, you have a concurrency problem when two (or more) people ask for a receipt at the same time. You have to use some sort of traffic control (a semaphore, record locking, whatever) to make sure anybody else that wants to get a number will wait until you've finished the reading, incrementing and writing of your new number. And if you throw the number away without using it, you can only back it out (set it back to the original number) if nobody's come after you. It's a chore, which makes the MySQL option even more appealing (they do all that for you).

My suggestion, if you need the number before you need the record, is to just create the record when you need the number and fill it with the other data when you are ready. If you want to abandon the transaction, you can just delete the record as-is and the number will get reused the next time around.

                                         ..KARL...

<SPAN ATTRIB="DORK">KarlGG</SPAN>





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to separate Multiple InvoiceNos of one Receipt Rg2005 SQL Server 2005 0 October 19th, 2007 02:29 AM
printing a receipt abdrabaa C# 1 September 12th, 2007 03:22 AM
Number Sequence Generator Peso SQL Server 2000 4 May 11th, 2006 01:36 PM
How to read Hard Disk sequence number by Java? Edward King J2EE 1 September 19th, 2005 03:29 PM
Return receipt Persits ASPEmail Haroldd Classic ASP Components 1 March 10th, 2004 11:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.