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

how to create a text box that generates auto number

P: 1
hi , im a new in php. id like to know how to create a textbox that generates auto number for every new record to be inserted.

Feb 28 '07 #1
Share this Question
Share on Google+
4 Replies

P: 11
you are a little vauge but I believe all you need is a counter.

say $count=0 then when you need a new text file, say $count++

This probably isn't what you are actually asking for, but i'm a little confused on your question.
Feb 28 '07 #2

Expert 2.5K+
P: 4,258
What "record to be inserted" are you talking about?
A database, a text file, ???

Ronald :cool:
Feb 28 '07 #3

P: 2
You do not need to do this. When you insert the record, the database will automatically generate the autonumber required and report it back to you. It is much easier to report this information AFTER the insert has been done.

If you want to report it before the insert, then you actually have to insert a blank record to 'reserve' the autonumber. Without the proper care, this leaves blank records, incomplete data, or non-sequential records in your database. In other words, you can get the autonumber before inserting, but you have to make sure you are managing it correctly.
Feb 28 '07 #4

Expert 2.5K+
P: 4,258
If you want to know the next insert id before having done the actual insert, use MySQL's own table status and try the following code:
$tablename = "tablename";
$next_increment = 0;
$qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
$qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );

$row = mysql_fetch_assoc($qShowStatusResult);
$next_increment = $row['Auto_increment'];

echo "next increment number: [$next_increment]";
?> [/php]

Ronald :cool:
Feb 28 '07 #5

Post your reply

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