Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generating Consecutive Numbers

Posted on 2004-04-15
14
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

722 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