• 0

serialize and unserialize problem (Jquery AJAX)


Question

hi guys i have a problem and here it is i am makeing a website with draggable boxs lik this

$(function () {
	$(".draggable").draggable({
		containment: '#holder',
		grid: [ 20, 20 ],
		handle:'.box-header',
		cursor: 'move',
		stop : function(event,ui) {
         		var dragposition = ui.position;
         		var dragboxid = $(this).attr('id');
			$.ajax({
            			type: 'POST',
            			dataType: 'json',
            			url: My_Site+'/themes/mytheme-2/ajax.php',
            			timeout: 5000,
            			data: {
            				task:"Moved",
            				dragposition:dragposition,
            				user_id:User_ID,
            				dragboxid:dragboxid
            			}
        		});
         	}
    	});
});

as you can see when you finish moving the box it will log the position with AJAX here is the "ajax.php" file

if($_POST['task'] == 'Moved'){
$dragboxid 		= $_POST['dragboxid'];
$dragposition_left	= $_POST['dragposition'][left];
$dragposition_top	= $_POST['dragposition'][top];
$uid			= $_POST['user_id'];

$exist	= mysql_query("SELECT var1 FROM `jcow_mytheme` WHERE uid >= '$_POST[user_id]' LIMIT 1");
if(mysql_num_rows($exist) == 0){
		$var1[$dragboxid] = array("pos_left"=>$dragposition_left,"pos_top"=>$dragposition_top);
		$var1e = serialize($var1);		
		mysql_query("INSERT INTO `".$table_prefix."mytheme` (uid, var1) VALUES('$uid', '$var1e' ) ");	
	}else{
		$row = mysql_fetch_array($exist);
		$var1d = unserialize($row['var1']);
		$var1d[$dragboxid] = array("pos_left"=>$dragposition_left,"pos_top"=>$dragposition_top);
		$var = serialize($var1d);			
		mysql_query("UPDATE `".$table_prefix."mytheme` SET var1='$var' WHERE uid='$_POST[user_id]'");
	}

}

this all works GREAT, but only once, the second time it wipes the array and starts again i will post some of the array to show my problem

first time

array(1) {
  ["notifications"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
}

second time

array(2) {
  ["notifications"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
  ["friends"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
}

Forth time

array(4) {
  ["notifications"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
  ["friends"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
  ["messages"]=>
  array(2) {
    ["pos_left"]=>
    string(1) "0"
    ["pos_top"]=>
    string(2) "20"
  }
  ["search"]=>
  array(2) {
    ["pos_left"]=>
    string(2) "20"
    ["pos_top"]=>
    string(2) "20"
  }
}

and the wierd one Fifth one

array(1) {
  ["new_member"]=>
  array(2) {
    ["pos_left"]=>
    string(3) "-20"
    ["pos_top"]=>
    string(2) "20"
  }
}

HELP PLEASE lol

thanks guys

 

1 answer to this question

Recommended Posts

  • 0

WAIT A MIN... i dont understand arrays fully but it it right that...
first

array([color=#ff0000]1[/color]) {
  ["notifications"]=>
  array([color=#ff0000]2[/color]) {
        ["pos_left"]=>
        string(1) "0"
        ["pos_top"]=>
        string(2) "20"
  }
}

and

array([color=#ff0000]4[/color]) {
  ["notifications"]=>
  array([color=#ff0000]2[/color]) {
        ["pos_left"]=>
        string(1) "0"
        ["pos_top"]=>
        string(2) "20"
  }
  ["friends"]=>
  array([color=#ff0000]2[/color]) {
        ["pos_left"]=>
        string(1) "0"
        ["pos_top"]=>
        string(2) "20"
  }
  ["messages"]=>
  array([color=#ff0000]2[/color]) {
        ["pos_left"]=>
        string(1) "0"
        ["pos_top"]=>
        string(2) "20"
  }
  ["search"]=>
  array([color=#ff0000]2[/color]) {
        ["pos_left"]=>
        string(2) "20"
        ["pos_top"]=>
        string(2) "20"
  }
}

the highlited RED numbers in the arrays is this correct???

[EDIT]--WHY color=#ff0000 INSTEAD OF RED??

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.