Best way to save a ordered List to the Database while keeping the ordering

前端 未结 12 1092
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 17:27

I was wondering if anyone has a good solution to a problem I\'ve encountered numerous times during the last years.

I have a shopping cart and my customer explicitly

12条回答
  •  时光取名叫无心
    2020-11-30 18:01

    Well, I would say the short answer is:

    Create a primary key of autoidentity in the cartcontents table, then insert rows in the correct top-down order. Then by selecting from the table with order by the primary key autoidentity column would give you the same list. By doing this you have to delete all items and reinsert then in case of alterations to the cart contents. (But that is still quite a clean way of doing it) If that's not feasible, then go with the order column like suggested by others.

提交回复
热议问题