php->xml childReplace

Hello,
I am trying to setup a user controllable display for my company, i have figured out how to make the php edit my xml file but it seems to just keep adding the data to the xml and i cant use spry:get on the lcd html to load the latest info. Basically i need my loading guys to be able to update the index page on an iphone and then have the data show up on the lcd. I would also greatly appreciate if someone could help me code that if there is a blank entry the xml doesnt update that line of information. here is what i am using.

Thanks in advance

Index.php

[code]

3Js Load Form <?php if(isset($_REQUEST['submit'])){ $xml = new DOMDocument("1.0","UTF-8"); $xml->load("a.xml");
$rootTag = $xml->getElementsByTagName("document")->item(0);

$dataTag = $xml->createElement("data");

$aTag = $xml->createElement("a",$_REQUEST['a']);
$bTag = $xml->createElement("b",$_REQUEST['b']);
$cTag = $xml->createElement("c",$_REQUEST['c']);
$dTag = $xml->createElement("d",$_REQUEST['d']);
$eTag = $xml->createElement("e",$_REQUEST['e']);
$fTag = $xml->createElement("f",$_REQUEST['f']);
$gTag = $xml->createElement("g",$_REQUEST['g']);
$hTag = $xml->createElement("h",$_REQUEST['h']);
$iTag = $xml->createElement("i",$_REQUEST['i']);
$jTag = $xml->createElement("j",$_REQUEST['j']);
$kTag = $xml->createElement("k",$_REQUEST['k']);
$lTag = $xml->createElement("l",$_REQUEST['l']);

$dataTag->appendChild($aTag);
$dataTag->appendChild($bTag);
$dataTag->appendChild($cTag);
$dataTag->appendChild($dTag);
$dataTag->appendChild($eTag);
$dataTag->appendChild($fTag);
$dataTag->appendChild($gTag);
$dataTag->appendChild($hTag);
$dataTag->appendChild($iTag);
$dataTag->appendChild($jTag);
$dataTag->appendChild($kTag);
$dataTag->appendChild($lTag);

$rootTag->appendChild($dataTag);

$xml->save("a.xml");

}

?>

Loading 1 Loading 2
Door Door
Trailer Trailer
Store Store
Loading 3 Loading 4
Door Door
Trailer Trailer
Store Store
[/code]

a.xml

<?xml version="1.0"?> <document> <data><a>1</a><b>1</b><c>1</c><d>1</d><e>1</e><f>1</f><g>1</g><h>1</h><i>1</i><j>1</j><k>1</k><l>1</l></data> </document>

loads.html(this is the lcd’s html)

[code]

3Js Loading Site

Loading 1

Loading 2

Door

{a}

Door

{d}

Trailer

{b}

Trailer

{e}

Store

{c}

Store

{f}

Loading 3

Loading 4

Door

{g}

Door

{j}

Trailer

{h}

Trailer

{k}

Store

{i}

Store

{l}

[/code]

There are actually a few ways to improve on this, but I’m short on time.

First I want to understand the issue. This is to see what trailers are being loaded/ unloaded in real time? Someone with a mobile device updates the data and it should route back to the main display (lcd)? Is that correct?

that is correct. It should be a very simple project but i am just learning php on the fly

Okay, now that I understand:

One thing to understand with web applications, the content is static in one form or another without outside influence to change that. What I mean by that is, your loads.html page is static as soon as it is rendered.

To overcome that, you would need to choose a route to take. If no one else is utilizing it other than to watch, you could refresh the page every N seconds/ minutes. That would rebuild the document every time it refreshes and would basically check for updates on each refresh. In which case you would do something like this,

[php] // replace the N with the number of seconds to wait[/php]

Another would be to use ajax. You could check the document, and update what was changed. This is a bit more complicated, but works better and does not require the entire page to be reloaded.

i understand the refresh part but what i am having a problem with is if the data gets added it just adds another line to the loads sheet and that will get confusing. what i am trying to figure out is how to make spry: pull latest data not all data. and also if there is no data in a form line then it would leave the data the same.

maybe if i could make my xml look like this it would be better. or would it be better to have a xml for each loading sheet and have it store them independently? also now that ive shown my floor supervisor this he wants me to build him a site that lets him pull the data by date, so he can go back and see what order the truck was loaded, when, and what door it was in. Im thinking i might need to change this to a sql so it becomes easier to store and access.

[code]<?xml version="1.0"?>



w15w23


w19w38 [/code]

Currently, you are just creating elements. When what you want to do is to compare them first.

I am rewriting the system a bit for usability.

Here is one place to look, http://www.w3schools.com/dom/dom_nodes_replace.asp.

I would suggest renaming you variables and look into arrays. To get the XML tags named how you want, you need to change the values from letters to those values.

so i should have tags and nodes to keep data better accessible? like have a node for trailer number then add tags inside that have the store number? also once i have this information how do i make the loads.html display only the latest and most current data for that loading number?

At the very least, it makes it more readable.

like have a node for trailer number then add tags inside that have the store number?

Sort of. I would go with,

[php]




















[/php]

also once i have this information how do i make the loads.html display only the latest and most current data for that loading number?

The data the loads.html page pulls is directly related to what is in the XML file and the backend will handle what is in that file.

You could go json in place of XML, less external sources are required, but that is your decision.

I tend to think a problem through to the nth degree, but I can have something worked up shortly.

then i will need to learn java scripting wouldn’t i? im just trying to get the basics of the page to work so i can give him something to work with. Once this goes live it might not make it very far before they scrap the whole thing or change every aspect.

That being said i am a very good copy cat and i learn quickly from seeing what others compile. Once i get the basic understanding of what they did to produce the outcome they got to i tear it apart for pieces that suit what i am working on. I just dont know where to find someone that is doing what we are looking for. I do appreciate the work you are putting into my problem.

I would make some changes to this, if I was to use it. It is missing the validation and error checking that it should have and it also recreates the json data each time. So, if something is not in the box when submitted, it is removed from the file.

But, you can pick through it. It is done using bootstrap3 for the LCD side. It uses an API back-end, meaning it can be used for any front-end situation without needing to alter the back-end.


Logistics.zip (1.85 KB)

Files uploaded…

thank you very much. This is way sleeker than what i was originally doing. Where should i look to learn how to only update content if nothing is input in the box. Or is there a way to make the box not clear after submit, or have the text box pre fill in with what is in the api folder?

You can, you would need the form to call the api.txt file and fill the textbox values with the element values.

Sponsor our Newsletter | Privacy Policy | Terms of Service