By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Passing value to php is undefined

100+
P: 178
Hi I am not sure where I am going wrong here maybe someone can help me.

I generate objects in my code using the following function (This works)
Expand|Select|Wrap|Line Numbers
  1. function showObject (){
  2.     document.getElementById('objName').value = "";
  3.     if (request.readyState == 4) {
  4.     var returned = request.responseText;
  5.     var splitResult = returned.split(" ");
  6.     var h = splitResult[0];
  7.     var w = splitResult[1];    // the dimensions must be set to a scale as they are to big for the screen. 20px represents 100mm
  8.     h = h/5;
  9.     w = w/5;
  10.  
  11.     cv = document.getElementById("canvas");
  12.     var newObject = document.createElement('div');
  13.     newObject.Class = "component";
  14.     newObject.id = g_objName;
  15.     newObject.innerHTML = g_objName;
  16.  
  17.     newObject.style.height = h;
  18.     newObject.style.width = w;
  19.     newObject.onmousedown=function(){grab(this);}    
  20.     cv.appendChild(newObject);
  21. }
Once they have all been placed in the correct position this function is used to write the co ordinates back to my database.
Expand|Select|Wrap|Line Numbers
  1. function render() {
  2.         var arr = document.getElementsByTagName("div");
  3.         var data = {
  4.           'result[]' : [],
  5.           'xReturnValue[]': [],
  6.           'yReturnValue[]' : []
  7.         };
  8.  
  9.         for(var i = 0; i < arr.length; i++)
  10.         {
  11.            var xReturnValue = -10;
  12.            var yReturnValue = -5;
  13.            for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  14.            {
  15.               xReturnValue += elem.offsetLeft;
  16.               yReturnValue += elem.offsetTop;
  17.  
  18.            }
  19.            data['result[]'].push(arr[i].innerHTML);
  20.            data['xReturnValue[]'].push(xReturnValue);
  21.            data['yReturnValue[]'].push(yReturnValue);
  22.         }
  23.         $.post("render.php",data);
  24.  
  25.       }
heres the PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3. foreach($_POST['result'] as $n=>$result){
  4.   $xReturnValue = $_POST['xReturnValue'][$n];
  5.   $yReturnValue = $_POST['yReturnValue'][$n];
  6.   //do what you want with the data
  7.     $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'");
  8.  
  9. }
  10.  
  11. ?>
My objects name isnt getting passed from the render function to php. Or if it is Im not using it right. I placed alerts after line 21 function and the values of both xReturnValue and yReturnValue are correct arr[i].innerHTML shows 'undefined'. Is this the problem
Aug 8 '08 #1
Share this Question
Share on Google+
36 Replies


acoder
Expert Mod 15k+
P: 16,027
How does the $.post function pass the data values to render.php?
Aug 8 '08 #2

100+
P: 178
I'm not quite sure how it works. I had previously posted a problem as I was reading one line at a time through to mysql but the problem I was having was that only a few random lines where getting updated in my table. This was a solution that someone came up with.
Aug 11 '08 #3

acoder
Expert Mod 15k+
P: 16,027
It must be defined somewhere though for you to use it in your page. Are you using a JavaScript framework/library?
Aug 11 '08 #4

100+
P: 178
No. Could it be a JSON thing?
Aug 11 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Can you post the rest of your code if it's not too much. If it is, either link to a test page or attach the code here.
Aug 11 '08 #6

100+
P: 178
I cant really post the rest of the code cos theres over 1000 lines in that and you would need all the other files too. I have nowhere I can upload test files to either as this is an intranet based aplication. Do you have any ideas what I coud use for the rener function?
Aug 11 '08 #7

100+
P: 178
heres most of the code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Pricing System</title>
  4. <style type="text/css">
  5. legend {
  6.     font-family:Arial, Helvetica, sans-serif;
  7.     font-size: 60%;
  8.     letter-spacing: -1px;
  9.     font-weight: bold;
  10.     line-height: 1.1;
  11.     background: white;
  12.     padding: 2px 6px;
  13.     color:#006666;
  14. }
  15. div {
  16.     position: absolute;
  17.     background-color:white;
  18.     border:solid #006666 5px;
  19.     width:50px;
  20.     height:50px;
  21.     padding-left:10px;
  22.     padding-left:8px;
  23.     zIndex:1;
  24.     overflow: hidden;
  25.     cursor:pointer;
  26.     color:#006666;
  27.     font-size: 12px;
  28.     font-family:Arial, Helvetica, sans-serif;
  29. }
  30. #canvas {
  31.     position: absolute;
  32.     background-color:white;
  33.     border:solid #000066 2px;
  34.     top: 5px;
  35.     padding:0px;
  36.     width:100%;
  37.     height:470px;
  38.     float:left;
  39.     font-size: 8px;
  40.     font-family:Arial, Helvetica, sans-serif;
  41.     overflow: scroll;
  42. }
  43. #controls {
  44.     margin:auto;
  45.     padding:10px;
  46.     position: absolute;
  47.     width:100%;
  48.     top:475px;
  49.     background: grey; 
  50.  
  51.     height: 100px;
  52. }
  53. .clear {
  54.     clear:both;
  55. }
  56. .button {
  57.     width:100px;
  58. }
  59. .select {
  60.     width:210px;
  61. }
  62. label {
  63.     width:30px;
  64.  
  65.     margin-top:3px;
  66.     margin-right:2px;
  67.     padding-top:1px;
  68.     padding-left:6px;
  69.     float:left;
  70.     display: block;
  71.     font-family:Arial, Helvetica, sans-serif;
  72.     font-size: 100%;
  73.     font-weight: normal;
  74.     line-height: 1.1;
  75.     color:#006666;
  76. }
  77. fieldset {
  78.     border:0;
  79. }
  80. #fmodel {
  81.     position:absolute;
  82.     top:5px;
  83.     left:42%;
  84. }
  85. #ftype {
  86.     position:absolute;
  87.     top:5px;
  88.     left:0%;
  89. }
  90. #generate {
  91.     position:absolute;
  92.     top:5px;
  93.     left:83%;
  94. }
  95. #fsubtype {
  96.     position:absolute;
  97.     top:5px;
  98.     left:21%
  99. }
  100. #fname {
  101.     position:absolute;
  102.     top:5px;
  103.     left:64%;
  104. }
  105. #createModule {
  106.     position:absolute;
  107.     top:5px;
  108.     left:92%;
  109. }
  110. #fdescription {
  111.     position:absolute;
  112.     border:solid #000066 2px;
  113.     top:30px;
  114.     left:0%;
  115.     width:59%;
  116.     Height:80%;
  117.     color:#006666;
  118.     font-family:Arial, Helvetica, sans-serif;
  119.     font-weight: normal;
  120. }
  121. #xpos {
  122.     width:50px;
  123. }
  124. #ypos {
  125.     width:50px;
  126. }
  127. #finished {
  128.     position:absolute;
  129.     border:solid #000066 2px;
  130.     top:30px;
  131.     left:90%;
  132.     width:10%;
  133.     Height:80%;
  134.  
  135.     color:#006666;
  136.     font-family:Arial, Helvetica, sans-serif;
  137.     font-weight: normal;
  138. }
  139. #current {
  140.     position:absolute;
  141.     border:solid #000066 2px;
  142.     top:30px;
  143.     left:60%;
  144.     width:29%;
  145.     Height:80%;
  146.     color:#006666;
  147.     font-family:Arial, Helvetica, sans-serif;
  148.     font-weight: normal;
  149. }
  150.  
  151.  
  152.  
  153. </style>
  154. <script language="javascript" src="list.php"></script>
  155. <script type="text/javascript" src="text-utils.js"> </script>
  156. <script type="text/javascript" src="jquery.js"> </script>
  157. <script type="text/javascript" src="request.js"> </script>
  158. <script type = "text/javascript">
  159.  
  160. var g_objName, ss;
  161.  
  162. window.onload = function() {
  163.  
  164.     fillCategory(); 
  165.     init();
  166. }
  167. function obj_delete() {
  168.     var cv = document.getElementById('canvas');
  169.     var obj_name = document.getElementById("object").value;
  170.     var proj_id = document.getElementById("projID").value;
  171.     var url = "deleteObject.php?obj_name=" + escape(obj_name) + "&proj_id=" + escape(proj_id);
  172.     request.open("GET", url, true);
  173.     request.send(null);
  174.     del_obj = document.getElementById(obj_name);
  175.     var cv = document.getElementById('canvas');
  176.     cv.removeChild(del_obj);
  177. }
  178.  
  179. function get_description() {
  180. var model = document.getElementById("model").value;
  181. var url = "lookupdescription.php?model=" + escape(model);
  182. request.open("GET", url, true);
  183. request.onreadystatechange = updatePage;
  184. request.send(null);
  185. }
  186.  
  187. function updatePage() {
  188.     if (request.readyState ==4) {
  189.         var modeldescription = request.responseText;
  190.         var x = document.getElementById("description");
  191.         replaceText(x, modeldescription);
  192.         document.getElementById("objName").value = " ";
  193.     }
  194. }
  195. function createObject() {
  196.     var g_model = document.getElementById("model").value;
  197.     g_objName = document.getElementById("objName").value;
  198.     g_projID = document.getElementById("projID").value;
  199.     var url = "create_object.php?g_model=" + escape(g_model) + "&g_objName=" + escape(g_objName) + "&g_projID=" + escape(g_projID);
  200.     request.open("GET", url, true);
  201.     request.onreadystatechange = showObject;
  202.     request.send(null);
  203. }
  204. function showObject (){
  205.     document.getElementById('objName').value = "";
  206.     if (request.readyState == 4) {
  207.     var returned = request.responseText;
  208.     var splitResult = returned.split(" ");
  209.     var h = splitResult[0];
  210.     var w = splitResult[1];    // the dimensions must be set to a scale as they are to big for the screen. 20px represents 100mm
  211.     h = h/5;
  212.     w = w/5;
  213.  
  214.     cv = document.getElementById("canvas");
  215.     var newObject = document.createElement('div');
  216.     newObject.Class = "component";
  217.     newObject.id = g_objName;
  218.     newObject.innerHTML = g_objName;
  219.  
  220.     newObject.style.height = h;
  221.     newObject.style.width = w;
  222.     newObject.onmousedown=function(){grab(this);}    
  223.     cv.appendChild(newObject);
  224. }
  225. }
  226.  
  227. function render() {
  228.     var arr = document.getElementsByTagName("div");
  229.     var data = {
  230.         'result[]' : [],
  231.         'xReturnValue[]': [],
  232.         'yReturnValue[]' : []
  233.         };
  234.  
  235.     for(var i = 0; i < arr.length; i++)
  236.         {
  237.         var xReturnValue = -10;
  238.         var yReturnValue = -5;
  239.         for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  240.             {
  241.             xReturnValue += elem.offsetLeft;
  242.                yReturnValue += elem.offsetTop;
  243.  
  244.                }
  245.         data['result[]'].push(arr[i].innerHTML);
  246.         data['xReturnValue[]'].push(xReturnValue);
  247.         data['yReturnValue[]'].push(yReturnValue);
  248.         }
  249.     $.post("render.php",data);
  250.  
  251. }
  252.  
  253.  
  254. var mousex = 0;
  255. var mousey = 0;
  256. var grabx = 0;
  257. var graby = 0;
  258. var orix = 0;
  259. var oriy = 0;
  260. var elex = 0;
  261. var eley = 0;
  262. var algor = 0;
  263.  
  264. var dragobj = null;
  265.  
  266. function falsefunc() { return false; } // used to block cascading events
  267.  
  268. function init()
  269. {
  270.   document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  271.   update();
  272. }
  273.  
  274. function getMouseXY(e) // works on IE6,FF,Moz,Opera7
  275.   if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
  276.  
  277.   if (e)
  278.   { 
  279.     if (e.pageX || e.pageY)
  280.     { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
  281.       mousex = e.pageX;
  282.       mousey = e.pageY;
  283.       algor = '[e.pageX]';
  284.       if (e.clientX || e.clientY) algor += ' [e.clientX] '
  285.     }
  286.     else if (e.clientX || e.clientY)
  287.     { // works on IE6,FF,Moz,Opera7
  288.       mousex = e.clientX + document.body.scrollLeft;
  289.       mousey = e.clientY + document.body.scrollTop;
  290.       algor = '[e.clientX]';
  291.       if (e.pageX || e.pageY) algor += ' [e.pageX] '
  292.     }  
  293.   }
  294. }
  295.  
  296. function update(e)
  297. {
  298.   getMouseXY(e); // NS is passing (event), while IE is passing (null)
  299.  
  300.   document.getElementById('xpos').value = elex;
  301.   document.getElementById('ypos').value = eley;
  302.   document.getElementById('object').value = ss;
  303. }
  304.  
  305. function grab(context)
  306. {
  307.   document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  308.   dragobj = context;
  309.   ss = context.id;
  310.   dragobj.style.zIndex = 10; // move it to the top
  311.   document.onmousemove = drag;
  312.   document.onmouseup = drop;
  313.   grabx = mousex;
  314.   graby = mousey;
  315.   elex = orix = dragobj.offsetLeft;
  316.   eley = oriy = dragobj.offsetTop;
  317.   update();
  318. }
  319. function drag(e) // parameter passing is important for NS family 
  320. {
  321.   if (dragobj)
  322.   {
  323.     var jumpX = mousex - grabx;
  324.     var jumpY = mousey - graby;
  325.     jumpX = Math.floor(jumpX / 20) * 20;
  326.     jumpY = Math.floor(jumpY / 20) * 20;
  327.     elex = orix + jumpX;
  328.     eley = oriy + jumpY;
  329.     dragobj.style.position = "absolute";
  330.     dragobj.style.left = (elex).toString(10) + 'px';
  331.     dragobj.style.top  = (eley).toString(10) + 'px';
  332.   }
  333.   update(e);
  334.   return false; // in IE this prevents cascading of events, thus text selection is disabled
  335. }
  336.  
  337.  
  338. function drop()
  339. {
  340.   if (dragobj)
  341.   {
  342.     dragobj.style.zIndex = 0;
  343.     dragobj = null;
  344.   }
  345.   update();
  346.   document.onmousemove = update;
  347.   document.onmouseup = null;
  348.   document.onmousedown = null;   // re-enables text selection on NS
  349. }
  350. </script>
  351. </head>
  352. <body>
  353. <span id = "canvas">
  354.  
  355. </span>
  356. <span id = "controls">
  357.  
  358.     <FORM name="drop_list">
  359.         <fieldset id="ftype">
  360.         <label for="type">Type</label>
  361.         <span class="div_texbox">
  362.             <SELECT  id="Category" NAME="Category" onChange="SelectSubmenu();" class="select">
  363.             <Option value="">Select Type</option>
  364.             </SELECT>
  365.         </span>
  366.         </fieldset>
  367.         <fieldset id="fmodel">
  368.           <label for="mod_named">Model</label>
  369.             <span class="div_texbox">
  370.             <SELECT id="model" NAME="model" onChange="get_description();" class="select">
  371.             <Option value="">Select Model</option>
  372.             </SELECT>
  373.             </span>
  374.         </fieldset>
  375.         <fieldset id="fsubtype">
  376.           <label for="subtype">sub</label>
  377.             <span class="div_texbox">
  378.             <SELECT id="submenu" NAME="submenu" onChange="SelectModel();" class="select">
  379.             <Option value="">Select</option>
  380.             </SELECT>
  381.             </span> 
  382.         </fieldset>
  383.         <fieldset id="fname">
  384.         <label for="mod_name">Name</label>
  385.             <span class="div_texbox">
  386.                 <input name="objName" type="text" id="objName" value="">
  387.         </span>
  388.         </fieldset>
  389.         <input type = "button" value = "Generate" class="button" onClick = "createObject()" id="generate">
  390.         <fieldset id="fdescription">
  391.             <legend>Description</legend>
  392.             <span id="description"></span>    
  393.         </fieldset>
  394.         <fieldset id="current">
  395.             <legend>Current Module</legend>
  396.             <table width=100%>
  397.             <tr><td>
  398.             <label for="xpos">Position</label>
  399.             <input type = "text" value = "" name = "xpos" id = "xpos">
  400.             <input type = "text" value = "" name = "ypos" id = "ypos">    
  401.             </td></tr>
  402.             <tr><td>
  403.             <label for="object">Name</label>
  404.             <input type = "text" value = "" name = "object" id = "object">
  405.             <input type = "button" value = "Delete" class="button" onClick = "obj_delete()">
  406.             </td></tr>
  407.             </table>
  408.         </fieldset>
  409.         <fieldset id="createModule">
  410.             <input type = "button" value = "New Module" class="button" onClick = "window.open('createModule.php', 'NewModule', 'width=700, height=400, statusbar=yes')">
  411.         </fieldset>
  412.         <fieldset id="finished">
  413.             <legend>Finished</legend>
  414.             <input type = "button" value = "Render" onClick = "render ()" class="button">
  415.             <input type = "button" value = "Exit" onClick = "exit ()" class="button">
  416.         </fieldset>
  417.         <input type = "hidden" value = "<?php echo $_POST["proj_id_hidden"] ?>" name="projID" id="projID">
  418. </span>
  419. </form>
  420. </body>
  421. </html>
Aug 11 '08 #8

acoder
Expert Mod 15k+
P: 16,027
Ah, I see you're using jQuery - see this link. What did you want $.post to do?
Aug 11 '08 #9

100+
P: 178
Sorry, someone else posted that bit of code for me. I wasnt using jquery. Do you think you can help me?
Aug 11 '08 #10

acoder
Expert Mod 15k+
P: 16,027
Looking back at your first post:
My objects name isnt getting passed from the render function to php. Or if it is Im not using it right. I placed alerts after line 21 function and the values of both xReturnValue and yReturnValue are correct arr[i].innerHTML shows 'undefined'. Is this the problem
it does seem that this is indeed the problem. On the screen, can you see 'undefined' for the contents of the divs within the "canvas" span element?
Aug 11 '08 #11

100+
P: 178
yep. can u help? I prob need to rewrite that function
Aug 12 '08 #12

acoder
Expert Mod 15k+
P: 16,027
Check the value of g_objName because that is what's setting the innerHTML property of the divs.
Aug 12 '08 #13

100+
P: 178
Thats the value I want tho the innerHTML says undefined
Aug 12 '08 #14

acoder
Expert Mod 15k+
P: 16,027
From your code, it's being set from the objname text box value. Have you set a value before showObject() is executed?
Aug 12 '08 #15

100+
P: 178
No the value is assigned in showobject
Aug 12 '08 #16

acoder
Expert Mod 15k+
P: 16,027
Yes, but g_objName is set in createObject() on line 197. Check that it's set properly there.
Aug 12 '08 #17

100+
P: 178
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.
Aug 13 '08 #18

100+
P: 178
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.

Expand|Select|Wrap|Line Numbers
  1. function render() {
  2.     alert(g_objName);
  3.     var arr = document.getElementsByTagName("div");
  4.     var data = {
  5.         'result[]' : [],
  6.         'xReturnValue[]': [],
  7.         'yReturnValue[]' : []
  8.         };
  9.  
  10.     for(var i = 0; i < arr.length; i++)
  11.         {
  12.         var xReturnValue = -10;
  13.         var yReturnValue = -5;
  14.         for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  15.             {
  16.             xReturnValue += elem.offsetLeft;
  17.                yReturnValue += elem.offsetTop;
  18.  
  19.                }
  20.                alert(arr[i].innerHTML);
  21.         data['result[]'].push(arr[i].innerHTML);
  22.         data['xReturnValue[]'].push(xReturnValue);
  23.         alert(xReturnValue);
  24.         data['yReturnValue[]'].push(yReturnValue);
  25.         alert(yReturnValue);
  26.         }
  27.     $.post("render.php",data);
  28.     // this bit of code is using jquery 
  29. }
Heres the php code in question
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3. foreach($_POST['result'] as $n=>$result){
  4.   $xReturnValue = $_POST['xReturnValue'][$n];
  5.   $yReturnValue = $_POST['yReturnValue'][$n];
  6.   //do what you want with the data
  7.     $q = mysql_query("update object set xpos='$xReturnValue', ypos='$yReturnValue' where object_name = '$result'");
  8.  
  9. }
  10.  
  11. ?>
config.php works fine as I have used it throughout this program
Aug 13 '08 #19

acoder
Expert Mod 15k+
P: 16,027
So you're saying arr[i].innerHTML is no longer undefined?
Aug 13 '08 #20

100+
P: 178
Yeah. Dont know whats changed but its working now. lol. Just doesnt update my db. Problem must be in the php
Aug 13 '08 #21

acoder
Expert Mod 15k+
P: 16,027
Well, if the values passed are all fine and the call is OK, that just leaves the PHP code. Perhaps you should ask in the PHP forum.
Aug 13 '08 #22

100+
P: 178
OK will try that now. thanks.
Aug 14 '08 #23

100+
P: 178
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
Expand|Select|Wrap|Line Numbers
  1. function render() {
  2.  
  3.     var arr = document.getElementsByTagName("div");
  4.     var data = {
  5.         'result[]' : [],
  6.         'xReturnValue[]': [],
  7.         'yReturnValue[]' : []
  8.         };
  9.  
  10.     for(var i = 0; i < arr.length; i++)
  11.         {
  12.         var xReturnValue = -10;
  13.         var yReturnValue = -5;
  14.         for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  15.             {
  16.             xReturnValue += elem.offsetLeft;
  17.                yReturnValue += elem.offsetTop;
  18.  
  19.                }
  20.                alert(arr[i].innerHTML);
  21.                var result = arr[i].innerHTML;
  22.         data['result[]'].push(result);
  23.         data['xReturnValue[]'].push(xReturnValue);
  24.         alert(xReturnValue);
  25.         data['yReturnValue[]'].push(yReturnValue);
  26.         alert(yReturnValue);
  27.         }
  28.     $.post("render.php",data);
  29.     // this bit of code is using jquery 
  30. }
php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3.  
  4.  
  5. foreach($_POST['result'] as $n=>$result){
  6.    $xReturnValue = $_POST['xReturnValue'][$n];
  7.    $yReturnValue = $_POST['yReturnValue'][$n];
  8.    $q = mysql_query("UPDATE object SET xpos='$xReturnValue', ypos='$yReturnValue' WHERE object_name = '$result'");
  9. }
  10.  
  11. ?>
Aug 15 '08 #24

acoder
Expert Mod 15k+
P: 16,027
Does the first div display undefined or is it the name of the first object to be updated?
Aug 15 '08 #25

100+
P: 178
in the alerts it shows the correct information
Aug 15 '08 #26

acoder
Expert Mod 15k+
P: 16,027
OK, if you pass these same values in the same format to PHP without Ajax, does it (still not) work?
Aug 15 '08 #27

100+
P: 178
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?
Aug 18 '08 #28

acoder
Expert Mod 15k+
P: 16,027
The query seems simple enough. How did the thread in the PHP forum go?
Aug 18 '08 #29

100+
P: 178
hadnt much luck with it. Im thinking of rewriting my script all together
Aug 18 '08 #30

acoder
Expert Mod 15k+
P: 16,027
If you do, make sure you get the PHP working completely first, otherwise any Ajax code is not going to work as expected either.
Aug 18 '08 #31

100+
P: 178
I changed the code so and it worked fine. Thanks for all your help acoder.
Aug 19 '08 #32

acoder
Expert Mod 15k+
P: 16,027
Pleased for you that you've finally got it working :) What was the problem in the end?
Aug 19 '08 #33

100+
P: 178
I really dont know. What I had been doing was using an insert to add the first few items to each record and then using an update later to fill in the rest. I just got around it by using just one insert at the end. As far as I could see there was nothing wrong with the code but it will prob be more efficient this way now so all is good
Aug 19 '08 #34

acoder
Expert Mod 15k+
P: 16,027
OK, thanks for posting your solution.
Aug 19 '08 #35

100+
P: 178
Heres the code. I just removed the line from my other script with the update i it.


Expand|Select|Wrap|Line Numbers
  1. function render() {
  2.  
  3.     var arr = document.getElementsByTagName("div");
  4.     var proj = document.getElementById("projID").value;
  5.     var data = {
  6.         'result[]' : [],
  7.         'model[]' : [],
  8.         'xReturnValue[]': [],
  9.         'yReturnValue[]' : [],
  10.         'proj[]' : []
  11.         };
  12.  
  13.     for(var i = 0; i < arr.length; i++)
  14.         {
  15.         var xReturnValue = -10;
  16.         var yReturnValue = -5;
  17.         for(var elem = arr[i];elem != null;elem = elem.offsetParent)
  18.             {
  19.             xReturnValue += elem.offsetLeft;
  20.                yReturnValue += elem.offsetTop;     
  21.                }
  22.                var result = arr[i].innerHTML;
  23.                // alert(result);
  24.                var model = arr[i].Class;
  25.                // alert(model);
  26.                // alert(proj);
  27.         data['result[]'].push(result);
  28.         data['model[]'].push(model);
  29.         data['xReturnValue[]'].push(xReturnValue);
  30.         data['yReturnValue[]'].push(yReturnValue);
  31.         data['proj[]'].push(proj);
  32.         }
  33.     $.post("render.php",data);
  34.     alert("Render Complete");
  35.     // this bit of code is using jquery 
  36. }
render.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3.  
  4.  
  5. foreach($_POST['result'] as $n=>$result){
  6.     $model = $_POST['model'][$n];
  7.    $xReturnValue = $_POST['xReturnValue'][$n];
  8.    $yReturnValue = $_POST['yReturnValue'][$n];
  9.    $proj = $_POST['proj'][$n];
  10. mysql_query("INSERT INTO object (module_name, object_name, xpos, ypos, proj_id) VALUES ('".$model."', '".$result."', '".$xReturnValue."', '".$yReturnValue."', '".$proj."')");
  11. //      $q = mysql_query("UPDATE object SET xpos='$xReturnValue', ypos='$yReturnValue' WHERE object_name = '$result'");
  12. }
  13.  
  14. ?>
Aug 19 '08 #36

acoder
Expert Mod 15k+
P: 16,027
So you had that insert query line in there all along and didn't show us? ;)
Aug 19 '08 #37

Post your reply

Sign in to post your reply or Sign up for a free account.