Page 1 of 2

php random vs sequential numbers

Posted: Tue Jan 18, 2005 7:17 pm
by skydivelouie
If anyone can help that would be great.

I am using MMEX to post form info. It allows me to generate a submision ID randomly.

I am wanting the numbers to be sequential.

I have found TONS of info on generating random numbers but none on sequential.

$a=rand(100,1000); - Would creat a random number between 100 and 1000.

$a=rand(100,1000);$a++; - Only seems to increase the number by one, and does not continue to increase. It just repeats the same single increment.

How can I get the number to start at 100 and increase by 1 each time the form is submitted. Any help on this would be greatly appreciated.

Please help! I need someone smarter than me, and that's everyone.

Posted: Tue Jan 18, 2005 7:52 pm
by feyd
the last submission id would need to be tracked on the server, otherwise, it'd be completely random, or the same everytime.

Posted: Tue Jan 18, 2005 8:03 pm
by skydivelouie
Thanks for replying.

I don't have direct access to the server. I am using a 3rd party server.

Is there any commands I could add into the script that would simply allow the numbers to be sequenced in increments of 1.

Posted: Tue Jan 18, 2005 8:09 pm
by feyd
only during that session, or with that particular browser/machine/user combination..

Posted: Tue Jan 18, 2005 8:20 pm
by skydivelouie
What causes the script to be able to choose a random number, but won't allow a sequential number?

Posted: Tue Jan 18, 2005 8:30 pm
by feyd
the number isn't permanent. It dies when the page finishes processing.

Posted: Tue Jan 18, 2005 8:33 pm
by skydivelouie
How can it be made permanent?

Posted: Tue Jan 18, 2005 8:34 pm
by skydivelouie
Is there a way to use that '++' in a different manner to get the results I'm looking for? Or some sort of looping? Anything?

Posted: Tue Jan 18, 2005 8:40 pm
by feyd
how permanent do you want the number to be? Does it always need to be uniquely sequencial? Or is it okay to reset the number when the browser is closed?

Posted: Tue Jan 18, 2005 8:47 pm
by skydivelouie
It's being used as a unique order number. Each one needs to be different. For example, if a customer calls with a question about a particular order number, these numbers would all need to be different in order for me to differentiate between the other orders.

Posted: Tue Jan 18, 2005 8:51 pm
by feyd
then you need access to a database.

The only other option is creating a file on the server, it can store the number used, along with their information. This is usually called a flatfile, or flatfile database. I would highly suggest using a real database though, as flatfiles can have lots of problems with concurrent sessions.

Posted: Tue Jan 18, 2005 8:56 pm
by skydivelouie
I have access to MySql Databases.

What would I need to do to accomplish this?

Posted: Tue Jan 18, 2005 9:03 pm
by feyd
you'll need a table created where you have at least an id that is set to auto_increment. When a new record is created, that number will always be unique (outside of a few circumstances)

I would suggest creating this table with a field/column for each piece of information you want to keep on these customer orders.

A basic MySQL tutorial would probably be a good idea to walk through. There are many around the net. Once you have this stuff figured out, you can move into making insertion calls with php, then create a form to tell the script what to insert. These things should be covered in many of the tutorials.

Posted: Tue Jan 18, 2005 9:06 pm
by skydivelouie
Thank You.

I will look at some of the tutorials and attempt to apply this information.

Thanks again for your help.

If you could recommend a particular tutorial that would be great.

I will post again if I have any questions.

Posted: Tue Jan 18, 2005 9:11 pm
by feyd
well. although I haven't read it, we do have a 2 parter here:
viewtopic.php?t=24396

You can find part 2 in the tutorials section.