Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 19th, 2002, 11:39 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
Auto Increment Question

Is there a way to query what the next auto_increment number will be?

Reply With Quote
  #2  
Old November 19th, 2002, 11:44 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: Auto Increment Question

are you talkin like..
for($i=0; $i<100; $i+=2)
??.. you musn't be.. hmm too simple.

Reply With Quote
  #3  
Old November 20th, 2002, 12:28 AM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
RE: Auto Increment Question

No, I was vague in my question. In MySql. I need to know what the next auto_incement number will increment to. I am going to move this to database help

Reply With Quote
  #4  
Old November 20th, 2002, 01:23 AM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Auto Increment Question

select LAST_INSERT_ID();

Reply With Quote
  #5  
Old November 20th, 2002, 01:26 AM
bob0099 bob0099 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: manchester,n.h.,usa
Posts: 172 bob0099 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Auto Increment Question

and then add 1.

Reply With Quote
  #6  
Old November 20th, 2002, 01:30 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Auto Increment Question

I don't know of a definate way to get the next ID. Even if you could, you would run into problems because you couldn't place a lock on it. Who's to say that between the time you get it and the time you use it, it hasn't been used already?

That being said is there a special reason you need it before hand? Would getting it after an insert work?

Reply With Quote
  #7  
Old November 20th, 2002, 02:00 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Auto Increment Question

Another possibility is to use the PEAR DB class, it allows you to create sequences and find out the next sequence before using it....

http://pear.php.net/

Reply With Quote
  #8  
Old November 20th, 2002, 02:34 AM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
RE: Auto Increment Question

I just thought it would be nice to display the invoice# at the as they were taking the order on the phone. I also wanted to use the number within a app that has the id+an incrementing run number at date for tracking of production runs

Reply With Quote
  #9  
Old November 20th, 2002, 02:37 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Auto Increment Question

I would insert a dummy record, then update that record with the information from the order. That way, you get a lock on the invoice number and you know it isn't going to change.....

Reply With Quote
  #10  
Old February 16th, 2004, 12:53 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: Auto Increment Question

php Code:
Original - php Code
  1.  
  2. $result = mysql_query("SELECT id FROM test ORDER BY id desc LIMIT 1"); // Get last inserted auto_increment number from the table
  3. $row = mysql_fetch_array($result);
  4. $id = $row['id'];
  5.  
  6. $id++; // Add 1 to last inserted auto_increment number
  7.  
  8. mysql_query("INSERT INTO test(id) VALUES('$id')");

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Auto Increment Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway