Tech Support Guy banner
Status
Not open for further replies.
1 - 3 of 3 Posts

· Registered
Joined
·
3,421 Posts
Discussion Starter · #1 ·
I would like to auto increment a non-key field (Invoice Number) within a MySql table, but PHPMyAdmin complains thus:-
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
is there a workaround for this, without falling back to using the index-key as the invoice number?
 

· Registered
Joined
·
2,400 Posts
Jim, not really. Auto increment won't do what you want.The way I do it is with a query to the database to find the last invoice number and then add 1 to it. The query is

Code:
$result = mysql_query("SELECT invoice_number FROM {$table} ORDER BY invoice_number DESC LIMIT 1");
Then look at the appropriate array element (0) and increment it before writing the new record.

Alternatively you could have a table with just the last invoice number in a row in it then just use that. Seems like overkill to do it this way to me though.
 

· Registered
Joined
·
3,421 Posts
Discussion Starter · #3 ·
Totally cool answer as per usual from you Colin:up:
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top