Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Reorder list of data

    Hi there

    I am a novice with JavaScript, and I was wondering how I would reorder a list of data. I googled this and found some ways but none of them really applied to me.
    I have a database with names of courses (its for a restaurant), they all have an ID which ranges from 1-8 (I only have 8 courses so far). I can add and delete courses from this table but I would like to be able to reorder theses courses, in other words change their ID, without having to go into the database and manually change itself.

    Thank you

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Could you please post the code that you've done so far?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't actually have any code so far.. I was kinda hoping you could help me out with that....

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    It is not too easy to envisage what you are trying to do. Please give an example of the "before" and "after".

    You talk about a database. Surely this should be done server-side?


    "This is the worst disaster in California since I was elected." - California Governor Pat Brown, discussing a local flood

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so say I have a list of data in my database that looks like this:

    id course
    1 c1
    2 c2
    3 c3
    4 c4

    then I open up my page and change (which is want i want to do) the order in which they appear. So I drag/move/w.e the entries about so they look like this:

    id course
    3 c3
    2 c2
    1 c1
    4 c4


    I'd now like to be able to add this new order to the database, but change the id of each course so that order will change

    id course
    1 c3
    2 c2
    3 c1
    4 c4


    I hope this helps, im not the best at explaining sometimes =s

    Thanks

  • #6
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    I don't think you want to change the ID - you need an additional column in your database table which displays the sort order. As per other posts this is going to need some server side stuff.

    However, it's possible to do drag and drop with the aid of jQuery relatively simply , plus some AJAX to update your database - have a look at this - it's for changing the display order of some images - but the idea's the same.
    Last edited by SB65; 06-15-2010 at 12:48 PM.

  • #7
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    awesome, thank you for that link, i shall give it a go now


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •