By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

Auto Incremented Number Access

P: 5
Hi All...

I m developing a collection record module.

In which the invoice number field should be auto incremented....

My problem is :"How can i access the current+1 invoice number in new form entry which is to be filled"...

Pls help me with u r solutions....


Thanks All
Aug 3 '07 #1
Share this Question
Share on Google+
9 Replies


dafodil
100+
P: 392
After inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
  2.  
this will generate the last value that you auto_incremented
Aug 3 '07 #2

mwasif
Expert 100+
P: 801
My problem is :"How can i access the current+1 invoice number in new form entry which is to be filled"...
Why do you want current+1 invoice number?

Are you looking for this?
Aug 4 '07 #3

P: 5
Thanks for trying to help me....


Actually, i want the incremented value which is now assigned to the new form is visible for the executive, who fills the collection form....
Aug 6 '07 #4

P: 5
After inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
  2.  
this will generate the last value that you auto_incremented

But, Can i access this value in my html form......
Aug 6 '07 #5

dafodil
100+
P: 392
you need to store it in a variable. A variable in a web development language and display it.

If you're using php. You can store it to a varaiable and echo it out, to display it in html.
Aug 6 '07 #6

P: 5
you need to store it in a variable. A variable in a web development language and display it.

If you're using php. You can store it to a varaiable and echo it out, to display it in html.

Can u help me with example code...
Aug 6 '07 #7

dafodil
100+
P: 392
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
  2.  

Are you sure that code is what you need?


Ok here is a sample in php:

Expand|Select|Wrap|Line Numbers
  1. /*let's assume it's already connected to the database*/
  2.  
  3. $result = mysql_query( "INSERT INTO `pdt_tracker` (`Track_ID`) VALUES (NULL);" );
  4. $x = mysql_result(mysql_query( 'SELECT LAST_INSERT_ID()'),0);
  5.  
  6. /*it will automatically store value of the AUTOINCREMENT column for the last INSERT in $x */
  7.  
  8. echo $x; //display the value of $x
  9.  
Aug 6 '07 #8

P: 5
Expand|Select|Wrap|Line Numbers
  1. SELECT LAST_INSERT_ID();
  2.  

Are you sure that code is what you need?


Ok here is a sample in php:

Expand|Select|Wrap|Line Numbers
  1. /*let's assume it's already connected to the database*/
  2.  
  3. $result = mysql_query( "INSERT INTO `pdt_tracker` (`Track_ID`) VALUES (NULL);" );
  4. $x = mysql_result(mysql_query( 'SELECT LAST_INSERT_ID()'),0);
  5.  
  6. /*it will automatically store value of the AUTOINCREMENT column for the last INSERT in $x */
  7.  
  8. echo $x; //display the value of $x
  9.  

Thanks a lot buddy....
Aug 7 '07 #9

dafodil
100+
P: 392
Glad, that code helped you. Post again if you got problems.
Aug 7 '07 #10

Post your reply

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