• 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.
  • Posts

    • I don’t get why if I bought the game on the last get I needed to pay $40 to upgrade to the new version in the first place and people who love the game and play a lot would have upgraded already so this is just PR and a chance to grab new players who forgot the game long time ago I think
    • The term "use" is doing a lot of heavy lifting in that headline. "Use" can mean opening ChatGPT occasionally to ask for the definition of a word or information about a specific topic. If you frame the question around how many people use it as a daily driver in their work or personal lives, that number is a lot smaller. Those are the people who pay for AI. Nearly everyone else is happy to use it for free, but doesn't see enough value in it to pay for it.
    • No support for Windows Hello!
    • I think you meant the "ntfs3" driver, but yes there have been a lot of fixes for it in this release and previous releases, not 100% sure if the issue you mentioned is fixed though. In any case, the new "ntfs" driver in 7.1 doesn't have that issue (at least, no reports of such have come thru), but your kernel needs to explicitly enable support for the new driver first (like how CachyOS kernel has it), and you need to edit your mount points in /etc/fstab to use "ntfs" instead of the other drivers.
    • Epic Games says Unreal Engine 6 will help developers "build content faster" using AI models by Pulasthi Ariyasinghe Epic Games is rolling out the latest major update to Unreal Engine 5 today, and at the same time, the company also dropped some information on the next-generation version of the product, Unreal Engine 6. This was already revealed a few weeks ago alongside the new Rocket League upgrade reveal. The company says it is combining the features of Unreal Engine and Unreal Editor for Fortnite to create this new version of its popular media creation tool. On top of creating entire games, the new engine will also focus on letting developers operate large-scale live service titles more easily, whether by shipping content into their own ecosystems or into Fortnite. The use of large language models is also mentioned here, with Epic saying it will be a core part of the engine. "We see LLMs, generative AI models, and tools like Claude and Codex playing a central role in helping you build content faster while maintaining the creative control you need," adds the company. Here is the rundown of what's new about version 6 of Unreal Engine: With all these changes to the programming model, portability upgrades, and generative AI integration, Epic says the new version of the engine will "change a lot about how games are made." The company aims to ship Unreal Engine 6 into early access in late 2027, with a full release planned for 12-18 months later. Epic Games also dropped a lengthy blog post about the new Unreal Engine 5.8 update for game developers over here. The release is focused on delivering better performance, customization, and streamlined workflows for development teams. This will be the final major update for this version of the engine before Epic switches to focus fully on Unreal Engine 6's early access launch.
  • Recent Achievements

    • One Month Later
      Vincian earned a badge
      One Month Later
    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      502
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      86
    4. 4
      Steven P.
      67
    5. 5
      neufuse
      65
  • Tell a friend

    Love Neowin? Tell a friend!