I keep some articles in MySQL database as follows:
id subject body order_no
============================================
1 subject 1 body 1 1
2 subject 2 body 2 2
3 subject 3 body 3 3
4 subject 4 body 4 4
5 subject 5 body 5 5
articles are adding to the to the table with their order number. Every time a new record is added to the table the other records should be shifted down if the new record has an order number which has already existed in database. For example we have a new record as follows:
id subject body order_no
============================================
6 subject 6 body 6 3
in this case we are supposed to get the following outcome:
id subject body order_no
============================================
1 subject 1 body 1 1
2 subject 2 body 2 2
3 subject 3 body 3 4
4 subject 4 body 4 5
5 subject 5 body 5 6
6 subject 6 body 6 3
it must be considered that records can be deleted or updated at any time while it shouldn't affect on records ordering and output must be shown as above (there shouldn't be any gap between "order_no"s).
What is the best solution to implement it by php and mysql? and how should I change my tables structure to get the best performance while the number of records are increased by time.