Using JQuery to change database IDs


I’m not as strong on JQuery as I’d like to be so hope this all makes sense but I’d appreciate some guidance on the best way to go about the following project.

I’m working on a cms based website for writers and would like them to be able to reorder the chapters of a book. So, using php, they would be able to view the first 100 characters from each of the chapters they have written. Now what I’d like to do is for each of these chapters to be draggable with a jquery script and if they drop chapter 3 above chapter 2, the database will automatically be changed so that the chapter_id of 3 changes to 2 and all other chapters are incremented by 1.

I’m not looking for a complete solution, just some general pointers on the best scripts or methodologies to research.

Many thanks in advance for any tips.

Hi there,

This problem can be broken into two smaller ones:

[]Make an element on a web page draggable using jQuery with an event firing when dragging stops
]Update a MySQL database using jQuery
[/LIST]Point one:
If you don’t mind using plugins, I would recommend Draggable.
Here’s a demonstration of everything you need to accomplish the first part:

Point two:
jQuery is a client side JavaScript framework and doesn’t have direct access to MySQL.
Therefore you will need to look into pairing jQuery with PHP and MySQL.
Here is a tutorial to get you started:


Thanks Pullo,

Apprciate you taking the time to reply with such useful info - I’ll look into them.

Many thanks