How would I go about automatically shifting the auto-increment id element in my sql table after I delete an element?

Viewed 40

Let's say I have an SQL table for storing news article headlines that my webcrawler automatically appends to when it locates one of interest. (My table is called headlines). In my table, I have:

id headline
1 title1
2 title2
3 title3
4 title4
5 title5

Whenever my webcrawler appends a headline I don't like, I can run a short command that accesses the SQL and deletes whichever article I don't want in the table by headline.

Let's say that I were to run a command that enters the following into phpMyAdmin:

DELETE FROM headlines WHERE headline='title3'

To my understanding, it will delete the entry, but the table will end up looking like:

id headline
1 title1
2 title2
4 title4
5 title5

instead of:

id headline
1 title1
2 title2
3 title4
4 title5

Is there a way I can write a command in php that automatically edits and moves the id down, and changes the auto-margin to one less than what was previously (i.e: something to the extent of id--;)? Thank you!

0 Answers
Related