Gamerz Posted February 27, 2010 Share Posted February 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2010 Share Posted February 27, 2010 If your column is using the AUTO_INCREMENT attribute, you won't have any problems like this. Quote Link to comment https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/#findComment-1018875 Share on other sites More sharing options...
Gamerz Posted February 27, 2010 Author Share Posted February 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/#findComment-1019074 Share on other sites More sharing options...
fenway Posted February 27, 2010 Share Posted February 27, 2010 Huh? Quote Link to comment https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/#findComment-1019145 Share on other sites More sharing options...
zeodragonzord Posted March 1, 2010 Share Posted March 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/193543-mysql-same-id-for-two-rows-problem/#findComment-1020095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.