This is a discussion on Order in the row! within the MySQL forums, part of the Database Server Software category; --> Hey guys, I'm new here and I hope its OK if I tap a lil into your knowledge base. ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hey guys, I'm new here and I hope its OK if I tap a lil into your knowledge base. I have a table ID|Name|Job the ID is an int that auto increases and should stay the same for history record. Now I want to put order to the table. Not by ID, not by name, not by job. so I want to add a order collumn, but I'm not sure what values it should have. I want to list the names and decide to move them up or down in order. e.g. ID:1-Steve-Farmer (move up in order button)(move down in order button) ID:2-Jim-Hunter (move up in order button)(move down in order button) ID:3-Al-Baker (move up in order button)(move down in order button) then if i click the (move up in order button) from Jim the list would look like this ID:2-Jim-Hunter (move up in order button)(move down in order button) ID:1-Steve-Farmer (move up in order button)(move down in order button) ID:3-Al-Baker (move up in order button)(move down in order button) i hope you get the gist of what I want. so what values should i use and how should they change to get the effect I want? the list will probably be huge and its not really about jobs and names but i just used this as an example. Thanks for any ideas Mawk |
| |||
| On 15 May 2007 01:15:28 -0700, Mohawk Mawk <blessblessbless@gmail.com> wrote: >Hey guys, >I'm new here and I hope its OK if I tap a lil into your knowledge >base. > >I have a table > >ID|Name|Job > > >the ID is an int that auto increases and should stay the same for >history record. >Now I want to put order to the table. >Not by ID, not by name, not by job. >so I want to add a order collumn, but I'm not sure what values it >should have. >I want to list the names and decide to move them up or down in order. >e.g. > >ID:1-Steve-Farmer (move up in order button)(move down in order button) >ID:2-Jim-Hunter (move up in order button)(move down in order >button) >ID:3-Al-Baker (move up in order button)(move down in order >button) > >then if i click the (move up in order button) from Jim the list would >look like this > >ID:2-Jim-Hunter (move up in order button)(move down in order >button) >ID:1-Steve-Farmer (move up in order button)(move down in order button) >ID:3-Al-Baker (move up in order button)(move down in order >button) > >i hope you get the gist of what I want. >so what values should i use and how should they change to get the >effect I want? the list will probably be huge and its not really about >jobs and names but i just used this as an example. >Thanks for any ideas >Mawk You might need another field : parent, same type as your ID, and being unique. You also need a top-row with ID 0 or something of the kind you will never change. ID:0-EMPTY-EMPTY Parent:NULL ID:1-Steve-Farmer Parent : 0 ID:2-Jim-Hunter Parent 1 ID:3-Al-Baker Parent 2 Then when you hit on Jim to put it up, you update Jim and Steve, to have Jim having EMPTY as Parent, and Steve having Jim. Then you SELECT everything again, and you always ORDER BY Parent. |
| ||||
| On May 15, 10:11 am, subtenante <zzsubtenant...@gmail.com> wrote: > On 15 May 2007 01:15:28 -0700, Mohawk Mawk <blessblessbl...@gmail.com> > wrote: > > > > >Hey guys, > >I'm new here and I hope its OK if I tap a lil into your knowledge > >base. > > >I have a table > > >ID|Name|Job > > >the ID is an int that auto increases and should stay the same for > >history record. > >Now I want to put order to the table. > >Not by ID, not by name, not by job. > >so I want to add a order collumn, but I'm not sure what values it > >should have. > >I want to list the names and decide to move them up or down in order. > >e.g. > > >ID:1-Steve-Farmer (move up in order button)(move down in order button) > >ID:2-Jim-Hunter (move up in order button)(move down in order > >button) > >ID:3-Al-Baker (move up in order button)(move down in order > >button) > > >then if i click the (move up in order button) from Jim the list would > >look like this > > >ID:2-Jim-Hunter (move up in order button)(move down in order > >button) > >ID:1-Steve-Farmer (move up in order button)(move down in order button) > >ID:3-Al-Baker (move up in order button)(move down in order > >button) > > >i hope you get the gist of what I want. > >so what values should i use and how should they change to get the > >effect I want? the list will probably be huge and its not really about > >jobs and names but i just used this as an example. > >Thanks for any ideas > >Mawk > > You might need another field : parent, same type as your ID, and being > unique. > You also need a top-row with ID 0 or something of the kind you will > never change. > > ID:0-EMPTY-EMPTY Parent:NULL > ID:1-Steve-Farmer Parent : 0 > ID:2-Jim-Hunter Parent 1 > ID:3-Al-Baker Parent 2 > > Then when you hit on Jim to put it up, you update Jim and Steve, to > have Jim having EMPTY as Parent, and Steve having Jim. > > Then you SELECT everything again, and you always ORDER BY Parent. http://www.phpriot.com/d/articles/cl...jax/index.html |