Jump to content

update array


cleary1981

Recommended Posts

No probs,

 

<body>
<span id = "canvas">

</span>
<span id = "controls">

<FORM name="drop_list">
	<fieldset id="ftype">
	<label for="type">Type</label>
	<span class="div_texbox">
		<SELECT  id="Category" NAME="Category" onChange="SelectSubmenu();" class="select">
		<Option value="">Select Type</option>
		</SELECT>
	</span>
	</fieldset>
	<fieldset id="fmodel">
  		<label for="mod_named">Model</label>
    		<span class="div_texbox">
		<SELECT id="model" NAME="model" onChange="get_description();" class="select">
		<Option value="">Select Model</option>
		</SELECT>
		</span>
	</fieldset>
	<fieldset id="fsubtype">
  		<label for="subtype">sub</label>
    		<span class="div_texbox">
		<SELECT id="submenu" NAME="submenu" onChange="SelectModel();" class="select">
		<Option value="">Select</option>
		</SELECT>
		</span> 
	</fieldset>
	<fieldset id="fname">
	<label for="mod_name">Name</label>
    		<span class="div_texbox">
    			<input name="objName" type="text" id="objName" value="">
	</span>
	</fieldset>
	<input type = "button" value = "Generate" class="button" onClick = "createObject()" id="generate">
	<fieldset id="fdescription">
		<legend>Description</legend>
		<span id="description"></span>	
	</fieldset>
	<fieldset id="current">
		<legend>Current Module</legend>
		<table width=100%>
		<tr><td>
		<label for="xpos">Position</label>
		<input type = "text" value = "" name = "xpos" id = "xpos">
		<input type = "text" value = "" name = "ypos" id = "ypos">	
		</td></tr>
		<tr><td>
		<label for="object">Name</label>
		<input type = "text" value = "" name = "object" id = "object">
		<input type = "button" value = "Delete" class="button" onClick = "obj_delete()">
		</td></tr>
		</table>
	</fieldset>
	<fieldset id="createModule">
		<input type = "button" value = "New Module" class="button" onClick = "window.open('createModule.php', 'NewModule', 'width=700, height=400, statusbar=yes')">
	</fieldset>
	<fieldset id="finished">
		<legend>Finished</legend>
		<input type = "button" value = "Render" onClick = "render ()" class="button">
		<input type = "button" value = "Exit" onClick = "exit ()" class="button">
	</fieldset>
	<input type = "hidden" value = "<?php echo $_POST["proj_id_hidden"] ?>" name="projID" id="projID">
</span>
</form>
</body>
</html>

Link to comment
Share on other sites

heres a complete listing

<?php

if ($_COOKIE["auth"] == "1") {

} else {
//redirect back to login form if not authorised
header ("Location: loginform.html");
exit;
}

?>
<html>
<head>
<title>TES - Pricing System</title>
<style type="text/css">
legend {
font-family:Arial, Helvetica, sans-serif;
font-size: 60%;
letter-spacing: -1px;
font-weight: bold;
line-height: 1.1;
background: white;
padding: 2px 6px;
color:#006666;
}
div {
position: absolute;
background-color:white;
border:solid #006666 5px;
width:50px;
height:50px;
padding-left:10px;
padding-left:8px;
zIndex:1;
overflow: hidden;
cursor:pointer;
color:#006666;
font-size: 12px;
font-family:Arial, Helvetica, sans-serif;
}
#canvas {
position: absolute;
background-color:white;
border:solid #000066 2px;
top: 5px;
padding:0px;
width:100%;
height:470px;
float:left;
font-size: 8px;
font-family:Arial, Helvetica, sans-serif;
overflow: scroll;
}
#controls {
margin:auto;
padding:10px;
position: absolute;
width:100%;
top:475px;
background: grey; 

height: 100px;
}
.clear {
clear:both;
}
.button {
width:100px;
}
.select {
width:210px;
}
label {
width:30px;

margin-top:3px;
margin-right:2px;
padding-top:1px;
padding-left:6px;
float:left;
display: block;
font-family:Arial, Helvetica, sans-serif;
font-size: 100%;
font-weight: normal;
line-height: 1.1;
color:#006666;
}
fieldset {
border:0;
}
#fmodel {
position:absolute;
top:5px;
left:42%;
}
#ftype {
position:absolute;
top:5px;
left:0%;
}
#generate {
position:absolute;
top:5px;
left:83%;
}
#fsubtype {
position:absolute;
top:5px;
left:21%
}
#fname {
position:absolute;
top:5px;
left:64%;
}
#createModule {
position:absolute;
top:5px;
left:92%;
}
#fdescription {
position:absolute;
border:solid #000066 2px;
top:30px;
left:0%;
width:59%;
Height:80%;
color:#006666;
font-family:Arial, Helvetica, sans-serif;
font-weight: normal;
}
#xpos {
width:50px;
}
#ypos {
width:50px;
}
#finished {
position:absolute;
border:solid #000066 2px;
top:30px;
left:90%;
width:10%;
Height:80%;

color:#006666;
font-family:Arial, Helvetica, sans-serif;
font-weight: normal;
}
#current {
position:absolute;
border:solid #000066 2px;
top:30px;
left:60%;
width:29%;
Height:80%;
color:#006666;
font-family:Arial, Helvetica, sans-serif;
font-weight: normal;
}



</style>
<script language="javascript" src="list.php"></script>
<script type="text/javascript" src="text-utils.js"> </script>
<script type="text/javascript" src="jquery.js"> </script>
<script type="text/javascript" src="request.js"> </script>
<script type = "text/javascript">

var g_objName, ss;

window.onload = function() {

fillCategory(); 
init();
}
function obj_delete() {
var cv = document.getElementById('canvas');
var obj_name = document.getElementById("object").value;
var proj_id = document.getElementById("projID").value;
var url = "deleteObject.php?obj_name=" + escape(obj_name) + "&proj_id=" + escape(proj_id);
request.open("GET", url, true);
request.send(null);
del_obj = document.getElementById(obj_name);
var cv = document.getElementById('canvas');
cv.removeChild(del_obj);
}

function get_description() {
var model = document.getElementById("model").value;
var url = "lookupdescription.php?model=" + escape(model);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}

function updatePage() {
if (request.readyState ==4) {
	var modeldescription = request.responseText;
	var x = document.getElementById("description");
	replaceText(x, modeldescription);
	document.getElementById("objName").value = " ";
}
}
function createObject() {
var g_model = document.getElementById("model").value;
g_objName = document.getElementById("objName").value;
g_projID = document.getElementById("projID").value;
var url = "create_object.php?g_model=" + escape(g_model) + "&g_objName=" + escape(g_objName) + "&g_projID=" + escape(g_projID);
request.open("GET", url, true);
request.onreadystatechange = showObject;
request.send(null);
}
function showObject (){
document.getElementById('objName').value = "";
if (request.readyState == 4) {
var returned = request.responseText;
var splitResult = returned.split(" ");
var h = splitResult[0];
var w = splitResult[1];	// the dimensions must be set to a scale as they are to big for the screen. 20px represents 100mm
h = h/5;
w = w/5;

cv = document.getElementById("canvas");
var newObject = document.createElement('div');
newObject.Class = "component";
newObject.id = g_objName;
newObject.innerHTML = g_objName;

newObject.style.height = h;
newObject.style.width = w;
newObject.onmousedown=function(){grab(this);}	
cv.appendChild(newObject);
}
}

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;
				           
   			}
    	data['result[]'].push(arr[i].innerHTML);
    	data['xReturnValue[]'].push(xReturnValue);
    	data['yReturnValue[]'].push(yReturnValue);
    	}
    $.post("render.php",data);
     
}


var mousex = 0;
var mousey = 0;
var grabx = 0;
var graby = 0;
var orix = 0;
var oriy = 0;
var elex = 0;
var eley = 0;
var algor = 0;

var dragobj = null;

function falsefunc() { return false; } // used to block cascading events

function init()
{
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function getMouseXY(e) // works on IE6,FF,Moz,Opera7
{ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
}

function update(e)
{
  getMouseXY(e); // NS is passing (event), while IE is passing (null)

  document.getElementById('xpos').value = elex;
  document.getElementById('ypos').value = eley;
  document.getElementById('object').value = ss;
}

function grab(context)
{
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  dragobj = context;
  ss = context.id;
  dragobj.style.zIndex = 10; // move it to the top
  document.onmousemove = drag;
  document.onmouseup = drop;
  grabx = mousex;
  graby = mousey;
  elex = orix = dragobj.offsetLeft;
  eley = oriy = dragobj.offsetTop;
  update();
}
function drag(e) // parameter passing is important for NS family 
{
  if (dragobj)
  {
    var jumpX = mousex - grabx;
    var jumpY = mousey - graby;
    jumpX = Math.floor(jumpX / 20) * 20;
    jumpY = Math.floor(jumpY / 20) * 20;
    elex = orix + jumpX;
    eley = oriy + jumpY;
    dragobj.style.position = "absolute";
    dragobj.style.left = (elex).toString(10) + 'px';
    dragobj.style.top  = (eley).toString(10) + 'px';
  }
  update(e);
  return false; // in IE this prevents cascading of events, thus text selection is disabled
}


function drop()
{
  if (dragobj)
  {
    dragobj.style.zIndex = 0;
    dragobj = null;
  }
  update();
  document.onmousemove = update;
  document.onmouseup = null;
  document.onmousedown = null;   // re-enables text selection on NS
}
</script>
</head>
<body>
<span id = "canvas">

</span>
<span id = "controls">

<FORM name="drop_list">
	<fieldset id="ftype">
	<label for="type">Type</label>
	<span class="div_texbox">
		<SELECT  id="Category" NAME="Category" onChange="SelectSubmenu();" class="select">
		<Option value="">Select Type</option>
		</SELECT>
	</span>
	</fieldset>
	<fieldset id="fmodel">
  		<label for="mod_named">Model</label>
    		<span class="div_texbox">
		<SELECT id="model" NAME="model" onChange="get_description();" class="select">
		<Option value="">Select Model</option>
		</SELECT>
		</span>
	</fieldset>
	<fieldset id="fsubtype">
  		<label for="subtype">sub</label>
    		<span class="div_texbox">
		<SELECT id="submenu" NAME="submenu" onChange="SelectModel();" class="select">
		<Option value="">Select</option>
		</SELECT>
		</span> 
	</fieldset>
	<fieldset id="fname">
	<label for="mod_name">Name</label>
    		<span class="div_texbox">
    			<input name="objName" type="text" id="objName" value="">
	</span>
	</fieldset>
	<input type = "button" value = "Generate" class="button" onClick = "createObject()" id="generate">
	<fieldset id="fdescription">
		<legend>Description</legend>
		<span id="description"></span>	
	</fieldset>
	<fieldset id="current">
		<legend>Current Module</legend>
		<table width=100%>
		<tr><td>
		<label for="xpos">Position</label>
		<input type = "text" value = "" name = "xpos" id = "xpos">
		<input type = "text" value = "" name = "ypos" id = "ypos">	
		</td></tr>
		<tr><td>
		<label for="object">Name</label>
		<input type = "text" value = "" name = "object" id = "object">
		<input type = "button" value = "Delete" class="button" onClick = "obj_delete()">
		</td></tr>
		</table>
	</fieldset>
	<fieldset id="createModule">
		<input type = "button" value = "New Module" class="button" onClick = "window.open('createModule.php', 'NewModule', 'width=700, height=400, statusbar=yes')">
	</fieldset>
	<fieldset id="finished">
		<legend>Finished</legend>
		<input type = "button" value = "Render" onClick = "render ()" class="button">
		<input type = "button" value = "Exit" onClick = "exit ()" class="button">
	</fieldset>
	<input type = "hidden" value = "<?php echo $_POST["proj_id_hidden"] ?>" name="projID" id="projID">
</span>
</form>
</body>
</html>

Link to comment
Share on other sites

The situation now is that every record is now updating apart from the very first in every case. Can anyone explain why this is happening?

 

Heres the code (jquery)

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 
}

 

I am pretty sure that the problem lies in the javascript code

php

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.