Order images with jquery-ui shortable |
[eluser]Lykos22[/eluser]
Hi I 'd like some help please, as my skills in jquery are not so good. What I want to achieve is to change the order of the images like this example. My database looks like this: Code: table: Gallery I have also created these 2 views: - index.php Code: <!-- will display the ajax result --> - order_ajax.php Code: <?php if(count($images)>0): ?> I have also created and the order_ajax controller Code: public function order_ajax(){ So what I basicly want to do is to drag the images arround in order to change their order, and when I click the save button pass the (new) data/order to the controller and to store them in the database. How can I make this work? any help would be appreciated.
[eluser]noideawhattotypehere[/eluser]
View: Code: $('#save').click(function(){ Code: function method-where-we-save-order() {
[eluser]Lykos22[/eluser]
Thanks for the reply! I'm currently testing your code, and noticed that the order might have an error. I dumped the setting and here's what I've got: Code: // controller Shouldn't the order start from 1 (currently looks like is 0-indexed)?? Also I need to get the img_id ( the number only from the li_1 )
[eluser]noideawhattotypehere[/eluser]
No, it starts from 0 as its arrays key (which starts from 0 in php, just increment by one? or start ordering from 0, your choice.) If you want to get only number from li_x use either: Code: $id = substr($img, 3); Code: $id = explode("_", $img);
[eluser]Lykos22[/eluser]
Thanks again for the reply. I've tested the code and works fine! I thought that it was more correct if the order started from 1, but it works like this great! |
Welcome Guest, Not a member yet? Register Sign In |