Increasing Number Generator..

This is a discussion on "Increasing Number Generator.." within the PHP Forum section. This forum, and the thread "Increasing Number Generator.. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 1st, 2006, 21:10
Junior Member
Join Date: Jun 2006
Location: CA
Age: 21
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Increasing Number Generator..

Well, here I am again. I've gotten tons and tons of help from this forum thus far, but once again I find myself stumped.

Here's my situation. I've got a Work Order Request form up and working with everything except for something that can generate a Work Order number. I figure the simplest way to begin doing this is to use a script that starts with 1, and each time that the "Submit" button is used (and the script is ran successfully), it increases that number by 1, and then displays it on the final product.

Hope it makes sense. I figure it would be easiest to do within PHP.. however I'm not too sure what other language would be possible. Maybe HTML, though I'm not positive. Thanks for any help in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 1st, 2006, 22:25
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

You can't do what I think you are thinking because there is no comunication, as such, between one works order and the next.

You need to store the number in a database or in a flat file on your server.

Each time a works oreder is generated, you extract the stored number, add one and use it and return the new number to the store for next time.

You can devise a suitable number for example by preceding the 'generated' part by fixed characters, e.g.,

ORDER1234
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 1st, 2006, 22:53
Junior Member
Join Date: Jun 2006
Location: CA
Age: 21
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Alright, I gotcha. So, easiest way is to create a new table named, say, "WORNum". (Word Order Request Number).

From there I can recall that number, (somehow) add 1 to it, assign a variable to the new number, and then store the variable. Two questions for ya then..

First one, is how would I go about increasing a number? It sounds VERY simple, however I haven't had to do anything like this. Second, instead of using the INSERT command in my sql query, is there something I can use that will replace a current entry?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 2nd, 2006, 11:08
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Here are some concepts you need to incorporate into your code. I have not given you full detail just so you can paste and copy, otherwise you never learn. Use of php assumed.

$num = fetch from database;

$newnum = $num + 1;

use SQL command 'update' to return new value to database;

$ordnum = 'WORN'.$newnum;

Let us know how you get on.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 2nd, 2006, 14:04
New Member
Join Date: Aug 2006
Location: UK
Age: 21
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

EDIT: Read below.

You should be able to do it all in one query:
Code: Select all
mysql_query("UPDATE WORNum SET num=num+1 WHERE id='1' ");
Might work, cant really think of it off the top of my head. Just have the table with 2 fields, id and num.

Last edited by mtgmaster; Aug 2nd, 2006 at 14:54.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 2nd, 2006, 14:44
Junior Member
Join Date: Jan 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

You should absolutely not do the above suggestions if you are using a database. If you are using mysql then you should use an auto_increment column. You would use last_insert_id() to fetch the last row inserted into that column.

If you are using a database other than mysql then you should look into sequences.

If you were to do the above suggestions then you would have to guarantee you were always the only user of the database, otherwise you could insert a number and before you insert it or update it another user could use the same value to update a table. Your value would then be wrong. Auto_increment and sequences avoid this problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 2nd, 2006, 14:52
New Member
Join Date: Aug 2006
Location: UK
Age: 21
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Quote:
Originally Posted by guelphdad View Post
You should absolutely not do the above suggestions if you are using a database. If you are using mysql then you should use an auto_increment column. You would use last_insert_id() to fetch the last row inserted into that column.

If you are using a database other than mysql then you should look into sequences.

If you were to do the above suggestions then you would have to guarantee you were always the only user of the database, otherwise you could insert a number and before you insert it or update it another user could use the same value to update a table. Your value would then be wrong. Auto_increment and sequences avoid this problem.
Never knew about that, havent even heard of last_insert_id(). Im gonna look it up, could be useful. I would of thought it would do the query too fast for things like that to happen.

So OP, disregard my suggestion if you aren't the only person using the site.

Quote:
Originally Posted by guelphdad View Post
If you are using mysql then you should use an auto_increment column. You would use last_insert_id() to fetch the last row inserted into that column.
Do you mean use the auto_increment column so when a new row is inserted it has a the next ID up? Because I didnt think he was inserting a new row each time.

Last edited by mtgmaster; Aug 2nd, 2006 at 15:19.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 2nd, 2006, 15:52
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Quote:
Originally Posted by guelphdad View Post
You should absolutely not do the above suggestions if you are using a database. If you are using mysql then you should use an auto_increment column. You would use last_insert_id() to fetch the last row inserted into that column.

If you are using a database other than mysql then you should look into sequences.

If you were to do the above suggestions then you would have to guarantee you were always the only user of the database, otherwise you could insert a number and before you insert it or update it another user could use the same value to update a table. Your value would then be wrong. Auto_increment and sequences avoid this problem.
Whilst these are valid comments in the right cercumstances, I think you have misunderstood the requirements in this case and might be confusing the originator of the thread.

The originator of the thread is not looking, or so I assumed, to insert any new rows. They just want a record of the last number they used.

If SephirGaine would like to elaborate on their requirements then the suggestions might need to be reviewed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 4th, 2006, 21:07
Junior Member
Join Date: Jun 2006
Location: CA
Age: 21
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Alright, I went with the auto_increment column for this. Seems to work just fine, however is there any way to "reset" the numbers? Even if I delete the entries inside of my database (say, word order #6), the next one I generate will go back up to 7. Unfortunately this kind of makes testing rough, since we've already got 3 work orders in there, however if I delete the column and re-create it, my script seems to get messed up like no other. Kind of confusing..

But thanks for all the help. I ended up running this in mysql..

Quote:
ALTER TABLE WOR ADD work_order_num INT UNSIGNED AUTO_INCREMENT, ADD PRIMARY KEY(work_order_num)
So the work_order_num is the row that contains the numbers. So far so good, no real complaints with it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 4th, 2006, 22:02
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

If you are going to be working with databases regularly is suggest you get yourself a tool like SQLyog.

You will be amazed at how easy it is to construct and manage databases including deleting all your entries so far and auto increments starting from scratch again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 4th, 2006, 22:14
Junior Member
Join Date: Jun 2006
Location: CA
Age: 21
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

I'll have to do so. Right now I'm using a browser-based phpMyadmin, which is provided by my hosting service.. works alright so far. And I found that just deleting the row and then re-making it works just fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Aug 5th, 2006, 12:36
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Don't use your work order number as the primary key. You really shouldn't do it, anyway, as you are talking about two different concepts. Start the table with a primary key that has no other purpose and index the work order number column as "unique". If nothing else, your logs will be easier to decipher.

Have you thought about having a boolean "void" column, the way you would in a checkbook, so that you can have work order numbers with no work order?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Aug 5th, 2006, 16:14
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Increasing Number Generator..

Gah, sorry, you want to use auto-increment for the work orders, don't you? There are problems trying to use a second auto-increment column. I think it can be done in InnoDB but there might be complications. I just don't know, sorry.

My first try, I guess, would be to use the primary key for the work order number and have a boolean "void" column to indicate numbers without a work order. I really don't think I'd start trying to empty rows for retracted work orders.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
increasing, number, generator

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Images and Fonts obeying CSS when increasing but not when decreasing Phil Web Page Design 1 Jun 16th, 2008 11:48
Increasing variables in a maze game Freddie Flash & Multimedia Forum 0 May 25th, 2008 17:35
Useful 'loading' gif generator Aso Graphics and 3D 3 Nov 26th, 2007 23:15
increasing file size begeiste PHP Forum 3 Sep 30th, 2007 05:33


All times are GMT. The time now is 07:15.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42