coolego1 Posted June 27, 2007 Share Posted June 27, 2007 Hello, I am working on an inventory system where an item may come in out of order from the rest of its fellow objects. For instance, there could be item #1, item #2, item #5 and item #6. If a new item shows up, it should receive number 3. The next item should get number 4. After that the numbers would be 7,8,9 as you would expect... I'm sure there is code to check this nicely, but I don't know how to write it. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/ Share on other sites More sharing options...
pocobueno1388 Posted June 27, 2007 Share Posted June 27, 2007 Why don't you just store the items number in the database, and set the field to be a primary key that automatically increases with each new insert. Then it will do all the work for you. Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283654 Share on other sites More sharing options...
coolego1 Posted June 27, 2007 Author Share Posted June 27, 2007 I guess I didn't clarify. I want the numbers to always be less than 100. The numbers will be stored in a database, but the number only has 2 spots to be in (it's the end of an item number) so the number must remain less than 100. If an item is thrown out, its number will be released to be reused. Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283656 Share on other sites More sharing options...
teng84 Posted June 27, 2007 Share Posted June 27, 2007 that is easy if you just query for the id and the first output will perform the condition like when first minus second is >=1 or then insert the id as your desired number output1 - output2 output2 - output3 i just give the logic hope you get it Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283659 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 Your system doesn't seem to provide any advantage can you explain why you want this system? Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283660 Share on other sites More sharing options...
coolego1 Posted June 27, 2007 Author Share Posted June 27, 2007 OK, this is the system. I have a warehouse full of stuff. The stuff has an item ID on it. Each item ID is 6 characters long. The First 4 characters of the ID are used to identify the type of item. The last 2 numbers are unique to each item. In conjunction with the first 4 characters, the last 2 create a completely unique ID. I don't want to waste any of my numbers for these last 2 (because they can only be 00 to 99) and so if an item is thrown out, its ID number can be reused. I would like to keep track of all these unique numbers in a database and when new items come in, generate new 6 digit IDs for them. As I said, if numbers are: AB1402 AB1403 AB1406 AB1407 ... AB1499 There are numbers 01, 04, and 05 in there that can be reused. How can I decide that these numbers are reusable without a massive for loop? Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283672 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 why don't you append your system to allow a greater number of items appending can cause some unforseen side effects for cached data. Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283674 Share on other sites More sharing options...
coolego1 Posted June 27, 2007 Author Share Posted June 27, 2007 Well, this is a new system that is coming in on top of a pencil and paper system, so the items are already numbered. So as not to disturb the order of the universe in the warehouse, the numbering scheme needs to remain consistent... My ultimate question is: Is what I'm asking for possible? Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283683 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 yes, but the same can be accomplished adding a leading 0 to preexisting numbers and simply cropping it out for items already made. Is your idea practical no because it will end up causing you headaches down the road with cached data (including paper results) You learn really quickly 100 items isn't going to be enough and reusing numbers is a poor idea in generally because an item number is like a primary key. Link to comment https://forums.phpfreaks.com/topic/57361-sequential-numbering-out-of-sequence/#findComment-283685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.