No the value is assigned in showobject
Passing value to php is undefined
Collapse
X
-
-
It is working fine. I inserted an alert at the end of that function and it gave me the correct result. I also put the same alert at the start of the render function and that worked also.Comment
-
The values in the render funcion are all fine as I used the alerts as shown below and they all prduced the correct results. Does the problem lie in the php code.
Code:function render() { alert(g_objName); var arr = document.getElementsByTagName("div"); var data = { 'result[]' : [], 'xReturnValue[]': [], 'yReturnValue[]' : [] }; for(var i = 0; i < arr.length; i++) { var xReturnValue = -10; var yReturnValue = -5; for(var elem = arr[i];elem != null;elem = elem.offsetParent) { xReturnValue += elem.offsetLeft; yReturnValue += elem.offsetTop; } alert(arr[i].innerHTML); data['result[]'].push(arr[i].innerHTML); data['xReturnValue[]'].push(xReturnValue); alert(xReturnValue); data['yReturnValue[]'].push(yReturnValue); alert(yReturnValue); } $.post("render.php",data); // this bit of code is using jquery }
Code:<?php require "config.php"; foreach($_POST['result'] as $n=>$result){ $xReturnValue = $_POST['xReturnValue'][$n]; $yReturnValue = $_POST['yReturnValue'][$n]; //do what you want with the data $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'"); } ?>
Comment
-
Yeah. Dont know whats changed but its working now. lol. Just doesnt update my db. Problem must be in the phpComment
-
-
Hi,
My php seems to be working fine now. I think. All the records are updating except for the very first one. Heres my code now.
Jquery
Code:function render() { var arr = document.getElementsByTagName("div"); var data = { 'result[]' : [], 'xReturnValue[]': [], 'yReturnValue[]' : [] }; for(var i = 0; i < arr.length; i++) { var xReturnValue = -10; var yReturnValue = -5; for(var elem = arr[i];elem != null;elem = elem.offsetParent) { xReturnValue += elem.offsetLeft; yReturnValue += elem.offsetTop; } alert(arr[i].innerHTML); var result = arr[i].innerHTML; data['result[]'].push(result); data['xReturnValue[]'].push(xReturnValue); alert(xReturnValue); data['yReturnValue[]'].push(yReturnValue); alert(yReturnValue); } $.post("render.php",data); // this bit of code is using jquery }
Code:<?php require "config.php"; foreach($_POST['result'] as $n=>$result){ $xReturnValue = $_POST['xReturnValue'][$n]; $yReturnValue = $_POST['yReturnValue'][$n]; $q = mysql_query("UPDATE object SET xpos='$xReturnValue', ypos='$yReturnValue' WHERE object_name = '$result'"); } ?>
Comment
-
-
when i do that only random records get updated. I cant see any errors in any of the code. Cud this be a bug in mysql?Comment
-
Comment