Solved

Generating Consecutive Numbers

Posted on 2004-04-15
14
275 Views
Last Modified: 2010-05-18
I have an html form that will be accessed by many users. I want to add a field that will automatically generate consecutive tracking numbers beginning with 04-01. How can I accomplish this?
0
Comment
Question by:contesa
  • 5
  • 3
  • 3
  • +3
14 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
Comment Utility

you have to use some server-side scripting language like asp/php etc..
to do this.
0
 
LVL 3

Expert Comment

by:ljfernandez
Comment Utility
You will have to store the users' ids on the server side. Are you using any server programming on your site?

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
You will also have to store the number somewhere server side. a simple file of a table that associates the user and the number.  Depending on the environment and how you are going to use it, you might also be able to use environmental or global variables.

Cd&
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
If you just need a tracking number why not use the Session ID?
0
 

Author Comment

by:contesa
Comment Utility
The users accessing the form are many. I don't need user ids tied to the tracking numbers. I just need a number generated on the form so that I can track how many forms have been submitted.

How can I use the Session ID as a tracking number?

Be kind, I'm a newbie to programming.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
If you just need a count, then just put the number in a text file and update from you forms processing script.  Every submit has to go through the script, so that is the place to do it.

Cd&
0
 
LVL 2

Expert Comment

by:Fataqui
Comment Utility
Hi


What web programming language(s) do you have available on the server.


Fataqui!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:contesa
Comment Utility
Hi COBOLdinosaur and Fataqui,

I am new to this field. I am running my sites on a Windowss 2000 server. I didn't set up the server so I'm not sure what available. However, I can have my network manager install whatever I need.

COBOLdinosaur, how exactly do I code the text file?

I'd appreciate any  help you can offer.

Thank you.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
The file is easy just use notepad and put the starting number in it.  Then you just have to modify the script that processes the form to update the number in the file each time the form gets submitted to it.

Cd&
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility
Personally I'd suggest using a database for this. It might at first seem overkill, but if you simply use a file, you have to lock the file, before opening it. A _Simple_ database would be easeir. all you have to do is each time the script is run, execute  a query like:

update count_table set count_column=count_column + 1;

Databases generally do their own synchronising. By that I mean if two scripts open a file at the same time, and read the same value, they will both write a number one abve the original, when you want two above the orig. This is especially important on potentially busy sites.
0
 

Author Comment

by:contesa
Comment Utility
aolXFT,

Is using a database the only way to avoid writing one above the original instead of two if the form is accessed simultaneously by more than one user?

0
 
LVL 6

Accepted Solution

by:
aolXFT earned 500 total points
Comment Utility
It's not the only way, but it is probably the easiest.

If you are doing it through a flat file you have to lock the file whilst it is in use by one program, to prevent two programs from gaining access to it at the same time. Check out www.php.net/flock .

Alternatively if you didn't want to lock the file, you could simply on each invocation, add one character(lets say 'x') to the file. This would be fairly a fairly atomic operation, so it wouldn't really matter if two files wrote to the same file, at the same time, because they would both be simply appending, a letter. The downside to this is that the file could get fairly large, if you have a busy site(namely no_of_hits * 1byte). This can be an advantage however in that in order to see the amount of visitors you have all you have all you have to do is check the file size. I would NOT recommend this however for a busy site.

/**
 *
 * Code to add a letter to a file each time a file is accessed.
 * This code has not been tested, and the concept only occured to
 * the author halfway through writing the message on EE
 *
 * This code may not be used in connection to the Nuclear Industry or
 * anything else that could get me in trouble. By using this code the
 * user assumes full responsability, and concedes to the non-existance
 * of any implied, or stated warrenty.
 *
 * @author aolXFT@Experts-Exchange
 */
function add_visitor_record(){
      $filename = "visitor_record.dat";
      return fwrite(fopen($filename, "a"), 'x', 1);
}

function get_visitor_count(){
      return filesize("visitor_record.dat");
}
0
 

Author Comment

by:contesa
Comment Utility
Hi, AOLfxt

I haven't forgotten about this problem.  However, I'm working on the form mail issue right now and I don't want to add another variable until my query works correct in the script.

I will definitely try this solution as soon as I get the form mail issue to work right.

Thanks for all of your help.
0
 

Author Comment

by:contesa
Comment Utility
Hi AOLfxt,

Thank you very much for all of your help.  We are actually testing the accepted answer but at the same time we are working on a database. We have realized that a database is much better for this situation.

Thanks again.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now