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.
|
|
|
|
|
![]() |
||
Increasing Number Generator..
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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. |
|
|
|
|||
|
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 |
|
|||
|
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? |
|
|||
|
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. |
|
|||
|
Re: Increasing Number Generator..
EDIT: Read below.
You should be able to do it all in one query:
Last edited by mtgmaster; Aug 2nd, 2006 at 14:54. |
|
|||
|
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. |
|
|||
|
Re: Increasing Number Generator..
Quote:
So OP, disregard my suggestion if you aren't the only person using the site. 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. |
|
|||
|
Re: Increasing Number Generator..
Quote:
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. |
|
|||
|
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:
|
|
|||
|
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. |
|
|||
|
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.
|
|
||||
|
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. |
![]() |
| Tags |
| increasing, number, generator |
| Thread Tools | |
|
|
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 |
| Number not increasing | pas4472 | Introduce Yourself | 3 | Dec 5th, 2006 22:34 |