Solved

Generating Consecutive Numbers

Posted on 2004-04-15
14
276 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
ID: 10834505

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

Expert Comment

by:ljfernandez
ID: 10834533
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
ID: 10834825
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
ID: 10834918
If you just need a tracking number why not use the Session ID?
0
 

Author Comment

by:contesa
ID: 10836409
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
ID: 10836923
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
ID: 10838349
Hi


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


Fataqui!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:contesa
ID: 10842318
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
ID: 10844102
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
ID: 10849178
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
ID: 10859350
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
ID: 10859736
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
ID: 10889617
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
ID: 11031718
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML problem with Internet Explorer 7 40
RSS Feeds--IE 13 166
HTML Video won't Autoplay on site 6 25
Problem to page 4 74
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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)

911 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

17 Experts available now in Live!

Get 1:1 Help Now