Peki bu saçma bir soru gibi ses gidiyor, biliyorum. Bu muhtemelen yapmak için en belirgin şeylerden biridir, ama ben veritabanı girişlerini sıralama iyi bir yol ile gelip çalışıyorum.
Bu gibi bakarak resim tablosu:
entry_id | entry_data
-------------------------
1 | data1
2 | data2
... | ...
n | datan
entry_id is of course Primary Key with AI option so all entries have a unique id. Now. I want to order that data. Say I want entry_id = 2 to be first without changing its entry_id. Then the table needs another column to store order number. I tried 2 approaches.
entry_order_no: Bu temelde öğeleri sipariş numarasını tutacak. Herhangi yeni bir öğe her zaman sonuna eklenecektir.
left_id + right_id, bu yaklaşım phpBB tarafından kullanılır. Değil emin niçin bu olsa right_id gerektirir?
I seem to prefer the 1st approach, but how do you sort the data later. Let's assume I want to newly added item move from the last position, to say 2nd. Way I've been doing it I was using indexed tables, where index was order no. Each index contained associative array, that had entry_id. That way I "simply" did foreach loop with an UPDATE on all entries from 2nd place down. That may work for few rows. Maybe even tens. But what when you have hundreds? This seems highly inefficient then. Second one seems a bit better. But something still tells me there's a better approach.
Önerirsiniz lütfen.