Jump to content

MySQL - Same ID for two+ rows problem


Recommended Posts

So I have this PHP and MySQL script that lets users add data to a MySQL table. Every time the user adds a data, there is an ID row that will +1.

 

When the user deletes a data from a random row, then later adds a data...sometimes, the two ID's become the same. This troubles me really because in addition, I also have this PHP Reorder script I use...and this is depended on the ID's. So I can't have two same ID's.

 

So...my question is...I want to make a code that every time the user triggers a specific script, it will check if any two id is same, and if they are, PHP will edit ALL mysql rows id, and make them in order (1,2,3,4,5...) So any clue how I would do this?

Link to comment
https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/
Share on other sites

Alright, so if I use this auto increment...then I would have to setup the primary key for this column as well. And as I have tried it...the primary key matches the specified column with every column to see if the data is like the primary key column. But I don't want that. I only want to see if the ONE column has no like data.

 

EDIT: Oh, and if I use this primary key...when I have (1,2,....12, 13) it would stop and tell me that 2 and 12 are like. since they both have two in it. Any fixes?

No, 2 and 12 are not the same, it does not work that way.  You should use an integer column, set the AUTO_INCREMENT attribute, and set it as a primary key.  That way, each time you INSERT new rows into the table, you will have a new ID and it will not conflict with any previous one.  Hence, in your PHP code, you never directly set that column; whenever you add a new row, it will make one for you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.