i already have the id field which is auto increment primary key. I have another field that i want to be auto increment/autonumber but phpadmin/mysql doesn't allow? how else do i have a field with an autonumber?

Recommended Answers

All 4 Replies

why to do that
i'm sure there is another solution

i just need a field that adds 1 to the current integer.... auto increment does that perfectly, but it only allows 1?

The other solution would be to calculate the value using the auto incremented value i.e if your value started at 5 and the id was 7 instead of starting a count wasting db space just get the id and 5.

$new_num = $row + 5;

You can not have more than one auto-increment column in the same table in MySQL.

You could however do something like:

/*
  Table
  +-----------+------------+
  | RowId (AI)| RowCount   |
  +-----------+------------+
  | 1         | 37         |
  +-----------+------------+
  | 2         | 51         |
  +-----------+------------+
  | 3         | 26         |
  +-----------+------------+
*/

UPDATE Table SET RowCount = RowCount + 1 WHERE RowId = 1

That query would increment your rowcount by 1 each run.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.