Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 22nd, 2005, 10:16 AM
Registered User
Join Date: Apr 2005
Location: Denver, CO, USA.
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.


Reply With Quote
  #2 (permalink)  
Old April 25th, 2005, 02:02 AM
Registered User
Join Date: Apr 2005
Location: Anthony, New Mexico, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

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.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 01:05 PM.

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