• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sortable divs jquery and codeigniter

#1
[eluser]flashingback[/eluser]
Hello,

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.

Code:
$("#sortable").sortable({
        handle: ".h_ico",
        update: function(){
        
                    stringDiv = "";
                    $("#sortable").children().each(function(i) {
                      var li = $(this);
                     if(li.attr("class") == "project"){
                      stringDiv += " "+li.attr("id") + '=' + i + '&';
                      }
                    });
    
                     $.ajax({
                       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 :

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

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

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


Messages In This Thread
sortable divs jquery and codeigniter - by El Forum - 10-13-2008, 06:06 AM
sortable divs jquery and codeigniter - by El Forum - 10-13-2008, 06:22 AM
sortable divs jquery and codeigniter - by El Forum - 10-13-2008, 07:11 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.