• 0

Little bit of MySQL/PHP help


Question

Ok, I got the great website I'm making as a hobby kinda as I'm learning PHP and MySQL. Great combination, and I love them both.

Now I've been learning MySQL and have been creating stuff relying on that.

So, I store information in a table and have an auto_increment ing table (column name = id)

I've been messing around and adding and deleting rows with a php interface. But I want to know how to change my table so that I don't have gaps in it.

For example, my first row id=1 second id=3, then third id=20, fourth = 22. How do I make it so that I don't have gaps and the table reindexes or something everytime I delete a row.

I want row 1 id=1, row 2 id=2, row 3 id=3, etc.

But I need t obe able to delete things sometimes and I want the id numbers to fix themselves so they only count rows that are created.

Any suggestions?

I'm just looking for a mysql query or something that I can use to fix the table's id's :)

Thx for your help!

exien

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Well, the ID just comes from the cardinality of the column (aka, the last number used). In theory, you shouldn't even be messing with ID's. They're meant as a unique identifier to that row of data, and you don't want to misrepresent that data. There is no real easy way of doing this, short of a bitching php script that extracts all the data, drops and recreates the tables. But that'll be a bit overboard...

I know it's kinda annoying to look at, but when ID's go up a lot, then it tends not to matter :)

Link to comment
Share on other sites

  • 0

its there as a key so that you can call that entry and it wont change like you can make a static hyper link of page.php?id=1 and it will always get that result - it will probaly cause problems in the long run to keep changing them

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.