I have a phpmyadmin table with auto increment id. I display this entries 12 in each page, so 1-12 are in the first page 13-24 to the second page and so on. Each entry has a specific position so 1 is top left 4 is top right 9 is bot left and 12 is bot right. If one entry is deleted, (say entry with id=3) from the database, when displayed the entry position is left empty, because when it tries to get the information with databse id=3 it gets nothing. Is there a way when the row is deleted from the databse, to make everything after that entry in the database with -1 id?? so if i delete entry 3, entry 4 becomes the new entry 3, entry 5 becomes the new entry 4 and so on. Is there a function in phpmyadmin that does this or do i have to make my own, or is there a trick I can implement.
Asked
Active
Viewed 242 times
-1
-
3There is no such thing as "a phpmyadmin table". PhpMyAdmin is a graphical web-based tool for administering MySQL databases. – Lightness Races in Orbit May 19 '14 at 07:41
-
The question is "why" you need to do this.... an `id` should be exactly that, an `id`: it shouldn't matter if there are gaps, or the sequence of the values, the only thing that matters is that they should be unique..... and if you're using a relational database properly, changing these `id` values is guaranteed to cause problems – Mark Baker May 19 '14 at 08:15
-
i display the entries based on the id, which is not the primary key. its an auto incremented value that decides where to sort each entry. What I chose to do is remove ai, get the database size/rows and set the latest entry with an id of db.noOfRows+1. – hahaha May 19 '14 at 08:24
-
1@alexandros - lets hope you never have more than one user adding/deleting at the same time then – Mark Baker May 19 '14 at 10:31
1 Answers
1
try out below code
$deletedId = $id;
//here will be your delete query
//perform below update query after deleting the record
mysql_query("UPDATE $tbaleNAme SET id = (id-1) WHERE id > $deletedId");

Chirag Patel
- 111
- 6