473,769 Members | 7,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a Sequential ID Number

14 New Member
I was wondering if anyone could help me out with this problem. I have a script that has a bunch of code in it. For some reason the coder decided to use a hex for a id number (it's just a member number, nothing secret) anyway the code section that I want to change is this :
Expand|Select|Wrap|Line Numbers
  1. function createUniqueID($table, $column)
  2. {
  3. $maxTries = 10;
  4.  
  5. while(1)
  6. {
  7. if($maxTries <= 0)
  8. return false;
  9.  
  10. $uniqueID = substr(md5(uniqid(rand(), true)), 0, 8);
  11.  
  12. // check if this token does not exist in the table already
  13. $sql = "select $column from $table where $column="._q($uniqueID);
  14. $rs = (directory where code is located)::execute($sql, __FILE__, __LINE__);
  15. if(!$rs)
  16. {
  17. showMsg(L_G_DBERROR, 'error');
  18. return false;
  19. }
  20.  
  21. if($rs->EOF)
  22. return $uniqueID;
  23.  
  24. $maxTries--;
  25. }
  26.  
  27. return false;
  28. }
  29.  
I just want a 5 digit sequential number. Can someone tell me how to change this. I realize that auto_increment would work in the db, but, there is so much code that interrelates in the script I don't believe that removing this string would work properly. Thanks for any help.
Sep 10 '07 #1
24 9380
JeremyMiller
69 New Member
Your coder didn't use hex directly -- that's coming from the hashing function md5 which changes substantially as the input changes. If it's not something that has to be hidden why not add a 5 digit number to the db id?

For example, if you consistently add 50000 to the id, the number will always be 5 digits (unless your number of members causes it to go to 6 digits, of course).
Sep 10 '07 #2
cwfent
14 New Member
Your coder didn't use hex directly -- that's coming from the hashing function md5 which changes substantially as the input changes. If it's not something that has to be hidden why not add a 5 digit number to the db id?

For example, if you consistently add 50000 to the id, the number will always be 5 digits (unless your number of members causes it to go to 6 digits, of course).

Hi Jeremy,

Thank you for your response. My problem is that my member ids are coming like "3e45jk1p" what I want is for them to start at 1 and proceed sequentially from there. I don't necessarily need each id to be 5 digits long. I would just expect that I would not need to exceed 5 digits.
Sep 10 '07 #3
JeremyMiller
69 New Member
Oh, then either:

1) Use the current autoincrement field's value, or
2) create a new autoincrement field and use it's value.

If you're just using the value of the field, then #1 is the preferred way as #2 creates unnecessary duplication.
Sep 10 '07 #4
cwfent
14 New Member
So do I do that by just saying "$uniqueID=auto _increment" ? If so What if I want to start at ID, say 1001, how would I do that?
Sep 10 '07 #5
JeremyMiller
69 New Member
Well, you have to get the autoincrement field from the database and use that. If you want to start at some number, then I'd recommend using the addition that I recommended above in case there are any DB tables which rely on the current values in your database.
Sep 11 '07 #6
cwfent
14 New Member
Ok, I'll just start at 1 then. I appreciate the help Jeremy, but, I'm about as lost as I can be. Given that I have the above code now, what do I do to change it?
Sep 11 '07 #7
JeremyMiller
69 New Member
If you provide the database table structure, I could be of greater help there. PHPMyAdmin is available (or installable) in most places and exports the DB structure very nicely.
Sep 11 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, CW.

Have a look at this article.
Sep 11 '07 #9
cwfent
14 New Member
Thanks Jeremy. There are 32 tables on the db. The only 2 that I think that are relevant are the account table and the user table. The user table is basically the account table plus extra info for address, etc. Here is the structure for the account table:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `wd_g_accounts` (
  2.   `accountid` varchar(8) NOT NULL default '',
  3.   `name` varchar(100) NOT NULL default '',
  4.   `description` text,
  5.   `dateinserted` datetime NOT NULL default '0000-00-00 00:00:00',
  6.   `rstatus` tinyint(4) NOT NULL default '0',
  7.   PRIMARY KEY  (`accountid`),
  8.   UNIQUE KEY `name` (`name`),
  9.   UNIQUE KEY `IDX_wd_g_accounts1` (`accountid`)
  10. ) TYPE=MyISAM;
Sep 11 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
12711
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a block of "x" number of sequential part numbers - say for example 5. If my database had the following numbers available: 101 104 105 110
0
1561
by: allyn44 | last post by:
Hello, I have a situation where I have to create 20 labels for each instance of an ID-each of the 20 labels has a different test number on it but needs the same id and one of 3 project names--for each label I need: ID number Project name (there are currently 3 but will be more in the future) Test number: There are 20 different tests for each ID number
7
5234
by: GAVO. | last post by:
Hello every one I have a database with a form called "frmOrders" on that for I need to create a sequential number for each city apart from the original autonumber. So the table "tblorders" would look something like this: OrderID (Autonumber) SeqNo City 1 1 London 2 1 Madrid 3 ...
4
8839
by: James | last post by:
Hello there, Does anyone know how to create a sequential record number field in a query?? Thanks, James
15
5283
by: NomoreSpam4Me | last post by:
Hi there i have a little problem with my invoice. Here it is: i have a main menu with buttons, one of my button is "Create new invoice", when click on it a form pop up so i can enter my information and one of the field (the user cannot change the info in it.) is invoice #. Right now, everythime i click on "Create new invoice", the invoice # add 1. But my problem is sometime the employee dont fill it (for x reason) and shut it down,...
2
1767
by: Mike Kingscott | last post by:
Hi all, I'd building an app that posts to a web service. One of the things that is required in the soap header is a sequential number appended to a ref, i.e. "IGI1001", "IGI1002", etc. Obviously the first part of the reference ("IGI") stays the same, but I need an incrementing number generated. Now, I was thinking of doing this via a SQL database, but it would be an awful waste as there would only be one table and one stored procedure...
9
5181
by: Nooby | last post by:
New to Access here. I inherited a db that has the first column as an automatically generated sequential number. I want to bump it up, but for the life of me I can't figure out how to do it. Is this type of generation a built in function of Access? I'm sure it can be written manually, but I doubt someone took the trouble to do it... Can someone point me in the right direction to figure out how to change this number? Thank you one and all!...
1
2455
maxamis4
by: maxamis4 | last post by:
Hello folks, I have two forms a parent form and a subform. The parent form is an unbound form while the subform is a form that contains all a list of what I like to call 'in stock ' phone numbers. with in that subform the user has the ability to select between to radio buttons to do a bulk selection. The first option lets the user select the first X amount of numbers that he or she wants. The second option selects X amount of numbers but...
9
2948
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what I seek, but, as is rather typical, I could understand neither the question nor the answer. I am hopeful that someone in this forum can provide me with suitable guidance. THE ISSUE I am working in Access 2003. The database I am preparing...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10048
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.