473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting incremental ID number back after doing an INSERT?

40
Hi all,

Simple question, may be a simple answer (dunno) but here goes:

Let's say my table's key element is "id" and it's self-incrementing. After I do an INSERT into the table... is there a way to know what the id number that was generated was? Because I want to do another INSERT into another table based upon that id number.

Does mySQL return this value anywhere? Or is finding this id number more of a php thing? Thanks in advance.
Dec 17 '07 #1
1 1396
vozzek
40
Okay, I actually found the answer to my own question - so I'm posting it below:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $tablename = "tablename";
  3. $next_increment = 0;
  4. $qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
  5. $qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );
  6.  
  7. $row = mysql_fetch_assoc($qShowStatusResult);
  8. $next_increment = $row['Auto_increment'];
  9.  
  10. echo "next increment number: [$next_increment]";
  11. ?>
Thanks to all who read this anyway. :)
Dec 17 '07 #2

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

Similar topics

1
by: Jimmy Chen | last post by:
Recently I've done a db2 backup and restore/recovery, but the process for recovering the database was different than what I thought to be. here is what I did: DB2 is set in online mode -...
0
by: Willem | last post by:
Based on MK's TSI_SOON (http://www.trigeminal.com/)I've created a nifty little procedure that - whenever you compact you db you get an incremental backup copy. Given that you have a table with...
5
by: Joel Matthew | last post by:
My boss was asking about incremental backups. I was scratching my head, thinking that the transaction log and a backup policy (script) for each record set (sorry about the archaic terminology)...
3
by: Joe | last post by:
Hi All! I'm working on putting together our build process and incremental updates. I understand the way AssemblyVersion works but I'm not too clear as to how I can do incremental updates to the...
6
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
3
by: vulpes | last post by:
How do I implement the "incremental results" with a BackgroundWorker? Many pages, http://msdn2.microsoft.com/en-us/library/wewwczdw.aspx for example, tell that I should subclass the...
5
by: orabalu | last post by:
Hi Guys, Can you give me some examples for Incremental load in PL/SQL for Datawarehouse projects. Regards, Balu
12
by: magmike | last post by:
Accidentally deleted a record. Anyway to get it back? If not, I know the ID number - which is an autonumber field. Because of the related data from other tables, would I be able to create a new...
9
by: KDawg44 | last post by:
Hi, I have PHP function that adds a record to the database. The table has an ID that is AUTO_INCREMENT. Is there anyway to get that ID back when I do any kind of insert? That ID is a foreign...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.