Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1966 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

incrementing ids

Thread title: incrementing ids
Closed Thread    
    Thread tools Search this thread Display Modes  
04-21-2007, 09:28 PM
#1
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old  incrementing ids

how would i start a user id when then register at 10001 and then from there every user that registers itll add one.

for example
1st user - id = 10001
2nd user - id = 10002
3rd user - id = 10003
etc......

04-21-2007, 09:42 PM
#2
sketchie is offline sketchie
sketchie's Avatar
Status: Senior Member
Join date: Jul 2005
Location:
Expertise:
Software:
 
Posts: 835
iTrader: 1 / 100%
 

sketchie is on a distinguished road

  Old

Set the database to auto_increment & unique, start from 0 in the database, and in the actual script just pull it out and add 10000 to it...

04-21-2007, 09:46 PM
#3
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

dont use the auto_increment property, just use this code
PHP Code:
$count mysql_num_rows($query);
$count $count 10001;
mysql_query("INSERT INTO table VALUES ('$count'........)"); 
if you are going to delete rows, use this code
PHP Code:
$query mysql_query("SELECT id FROM table ORDER BY id DESC LIMIT 1");
$id mysql_result($query,'0',"id")+1;
mysql_query("INSERT INTO table VALUES ('$id'........)"); 
With this one you will have to start with one row in the database, id it 10000

04-21-2007, 09:50 PM
#4
Duality is offline Duality
Duality's Avatar
Status: Go Baby!!
Join date: Jul 2006
Location: Toronto, ON
Expertise:
Software:
 
Posts: 1,372
iTrader: 22 / 100%
 

Duality is on a distinguished road

Send a message via AIM to Duality Send a message via MSN to Duality Send a message via Yahoo to Duality

  Old

Originally Posted by Village Idiot View Post
dont use the auto_increment property, just use this code
PHP Code:
$count mysql_num_rows($query);
$count $count 10001;
mysql_query("INSERT INTO table VALUES ('$count'........)"); 
if you are going to delete rows, use this code
PHP Code:
$query mysql_query("SELECT id FROM table ORDER BY id DESC LIMIT 1");
$id mysql_result($query,'0',"id")+1;
mysql_query("INSERT INTO table VALUES ('$id'........)"); 
With this one you will have to start with one row in the database, id it 10000
Wow. This is very close to Turing and Visual Basic (I'm learning both in school.)

04-21-2007, 10:04 PM
#5
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

yeah thats how i was going to do it. with the adding 1 to each one.. but i didnt know if there was any easier way of doing it. Thanks.

04-21-2007, 10:14 PM
#6
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Originally Posted by Village Idiot View Post
dont use the auto_increment property
Why on earth not? Just specify the id when inserting the very first row, and leave it out from then on.

04-21-2007, 10:17 PM
#7
iisbum is offline iisbum
iisbum's Avatar
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
 
Posts: 273
iTrader: 4 / 100%
 

iisbum is on a distinguished road

  Old

Auto increments are definitely the safest way to handle incrementing values like this.

I believe you can tell MySQL to set the starting value of the auto_increment field:

ALTER TABLE tbl_name AUTO_INCREMENT = 10000;

HTH,
Mubs

04-24-2007, 02:11 AM
#8
bluesaga is offline bluesaga
Status: Member
Join date: Feb 2007
Location:
Expertise:
Software:
 
Posts: 137
iTrader: 1 / 100%
 

bluesaga is on a distinguished road

  Old

I agree with iisbum, and also far far faster.

Village Idiot:
Code:
$count = mysql_num_rows($query);
$count = $count + 10001;
I presume you have a query like:
Code:
SELECT * FROM table
Well, what happens if you have 10,000 rows? **** starts to get slower!

Id recommend using the count parameter and a query alike:
Code:
$query = mysql_query("SELECT count(*) as count FROM table");
$count = mysql_fetch_array($query);
$count = $count['count'];
$count = $count + 10001;

04-24-2007, 02:51 AM
#9
Dark_Prince11 is offline Dark_Prince11
Status: Member
Join date: Apr 2007
Location: Deer Park, NY
Expertise:
Software:
 
Posts: 123
iTrader: 0 / 0%
 

Dark_Prince11 is on a distinguished road

Send a message via AIM to Dark_Prince11 Send a message via MSN to Dark_Prince11

  Old

Are you talking about the index value in the SQL database because that is how I am understanding your question. If you want your index value to start from 10000 set the default value of that column to 10000. That's how it works for me at least, or you can just create a row with the index value of 10000 delete that row and everything after that auto-increments from 10000.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed