php random vs sequential numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

php random vs sequential numbers

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the last submission id would need to be tracked on the server, otherwise, it'd be completely random, or the same everytime.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

only during that session, or with that particular browser/machine/user combination..
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

What causes the script to be able to choose a random number, but won't allow a sequential number?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the number isn't permanent. It dies when the page finishes processing.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

How can it be made permanent?
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post by skydivelouie »

I have access to MySql Databases.

What would I need to do to accomplish this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
skydivelouie
Forum Newbie
Posts: 23
Joined: Tue Jan 18, 2005 7:07 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply