Re: running number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CREATE TABLE `users` (
  `num` int(10) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL default '',
  `login` varchar(100) NOT NULL default '',
  `password` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`num`),
  KEY `num` (`num`)
) TYPE=MyISAM AUTO_INCREMENT=12345 ;

That should help out. When creating the table in mysql you can set the auto_increment number on the last line, which when you add a new user the query looks like:

insert into users values('','name','login','pass');

leaving the first field empty makes it automatically increase it. The beauty is that you can have 40000000000 people registering at once, and their number gets assigned as the query is run against the database, no matter what order they hit it in, the system will take it as they come.

HTH,
Robert

Roger Thomas is quoted as saying on 7/25/2005 5:21 AM:
I am required to write a user registration script that captures the basics like name, phone number etc etc. I would also have to write to mySQL database a number that is associated with that user.

At this point of writing, the start of that number is unknown. But the number will be incremented by 1 after each successfull registration.

Let's say the number starts from 12345.

I am quite new at all these stuff and would like to seek your advise on the *recommended way* of achieving this. I am thinking along these lines:
a) store that number (12345) in a table
b) a user registers and assign that number to him
c) increment number to 12346
d) process repeats for the next registration

Concern: How do tell mySQL to lock the 'number' table when a new registration process is about to take place. Is locking the best option here or is/are there better ways?

Please advise.

--
Roger


---------------------------------------------------
Sign Up for free Email at http://ureg.home.net.my/
---------------------------------------------------


--
Robert Sossomon, Business and Technology Application Technician
4-H Youth Development Department
512 BrickHaven Drive Suite 220L, Campus Box 7606
N.C. State University
Raleigh NC 27695-7606
Phone: 919/515-8474
Fax:   919/515-7812
robert_sossomon@xxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux