Page 1 of 1
Very simple PHP increment, not MYSQL
Posted: Sat Apr 19, 2008 3:00 pm
by sean72
One of my intranet sites has a very simple, internal order form with a user group of around 50 people. I have been asked to make the simple PHP order form (which came pre-written but I have customized slightly) generate an automatic order number.
I would like to store the number in a simple txt or csv file (or similar), and for each order, load, increment, use and store it again. It would be ideal if there was some way to lock this file so we didn't get duplicates, but the likelihood of two users making an order at the same time are very low. I would need to insert this code segment or routine in the existing PHP file.
I studied programming, so I understand the concepts, but do not know the syntax for PHP very well. Code suggestions should be complete please.
Thank you!
Re: Very simple PHP increment, not MYSQL
Posted: Sun Apr 20, 2008 4:26 am
by markusn00b
sean72 wrote:One of my intranet sites has a very simple, internal order form with a user group of around 50 people. I have been asked to make the simple PHP order form (which came pre-written but I have customized slightly) generate an automatic order number.
I would like to store the number in a simple txt or csv file (or similar), and for each order, load, increment, use and store it again. It would be ideal if there was some way to lock this file so we didn't get duplicates, but the likelihood of two users making an order at the same time are very low. I would need to insert this code segment or routine in the existing PHP file.
I studied programming, so I understand the concepts, but do not know the syntax for PHP very well. Code suggestions should be complete please.
Thank you!
Slightly demanding..
Check php.net for the file() functions, using fopen(), fclose(), etc. you can write and save values to a file.
Re: Very simple PHP increment, not MYSQL
Posted: Sun Apr 20, 2008 11:04 am
by John Cartwright
also flock() for file locking
Re: Very simple PHP increment, not MYSQL
Posted: Sun Apr 20, 2008 1:26 pm
by sean72
I don't intend to sound demanding, if that's what you mean. I just don't know PHP very well but know that this is a relatively simple task.
Re: Very simple PHP increment, not MYSQL
Posted: Sun Apr 20, 2008 1:34 pm
by John Cartwright
Yes it a relatively simple task to do. That is all the more reason why we encourage you to take a stab at it. I'm sure I don't have to tell you, but we aren't here to write code for you. The purpose of these forums is to promote the learning of PHP. Now, that doesn't mean people won't write examples here and there, but outright asking for someone to do it for you is not going to fly.
Take a shot at it, and post a little code. We will nudge you along the way, of course. The functions we've mentioned already have examples in the
manual too.