Welcome Guest, Not a member yet? Register   Sign In
sortable divs jquery and codeigniter


I am trying to make a sortable image list with jquery and CI. I've got the jquery part working but the php part doesn't want to work. It seems to update the mysql table but not right

This is wat I have:

first of al jquery gets the positioning of the divs I have sorted on update.

        handle: ".h_ico",
        update: function(){
                    stringDiv = "";
                    $("#sortable").children().each(function(i) {
                      var li = $(this);
                     if(li.attr("class") == "project"){
                      stringDiv += " "+li.attr("id") + '=' + i + '&';
                       type: "POST",
                       url: "<?=base_url().'index.php/admin/updatelist'?>",
                       data: stringDiv,
                       success: function(msg){
                         alert( "Data Saved: " + msg );
                            [removed].reload( true );


So in the updatelist I receive something like this:

$_POST[0] = 1
$_POST[1] = 0
$_POST[2] = 2

updatelist method :

function updatelist () {
        $data =  $this->Projects->getList() ;
        foreach ( $_POST as $key => $value )
            $newrank = $data[$key]->rank;
            $rank = $data[$value]->rank;
            if($rank != $newrank){

and the switchProject method contains this (this probably contains the fault):

function switchProject ($rank,$newrank){
        $this->db->query("UPDATE gallery SET rank='".$newrank."' WHERE rank='".$rank."' ");

Can't you work with the id of the image? Then you can do
$this->db->query("UPDATE gallery SET rank='".$newrank."' WHERE id='".$id."' ");

I think the check to see if the list rank is changed should be dropped, if you just update each row the overhead will be more or less the same. You should benchmark it to see the results.

You are my hero, works like a charm

Theme © iAndrew 2016 - Forum software by © MyBB