[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."' ");
}