Results 1 to 7 of 7
Thread: PHP XML -
Hybrid View
-
12th June 2011 20:06 #1Registered User
Join Date: Jun:2011
Location: Sofia
Posts: 3
PHP XML -
!
, .
mysql c php XML DOM functions.
XML-a :
:Code:<markers> <DEVS DEVICE="DEV10"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A57" TIME="18:16:40" /> </DEVS> <DEVS DEVICE="DEV10"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> </DEVS> <DEVS DEVICE="DEV5"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> </DEVS> <DEVS DEVICE="DEV5"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> </DEVS> </markers>
TAG, Unique, , DEV10 1 DEV10, .Code:<markers> <DEVS DEVICE="DEV10"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A57" TIME="18:16:40" /> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> </DEVS> <DEVS DEVICE="DEV5"> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> <marker USER="PRIVET_!" DATA1="0578" DATA2="0A55" TIME="18:16:05" /> </DEVS> </markers>
, :
, .PHP Code:<?php
require("config.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ($server, $db_user, $db_pass);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM input WHERE (DEVS = 'DEV5' or DEVS = 'DEV10') ORDER BY TIME DESC";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node1 = $dom->createElement("DEVS");
$parnode->appendChild($node1);
$marker = $dom->createElement("marker");
$node1->appendChild($marker);
$marker->setAttribute("USER", $row['USER']);
$marker->setAttribute("DATA1", $row['DATA1']);
$marker->setAttribute("DATA2", $row['DATA2']);
$marker->setAttribute("TIME", $row['TIME']);
$node1->setAttribute("DEVICE", $row['DEVS']);
}
echo $dom->saveXML();
?>
-
12th June 2011 20:42 #2Registered User
Join Date: Dec:2003
Posts: 2,817
- ? DOMDocument ?
Gigabyte DS3P, E4400@9x333, 2x2Gb Super T@1000Mhz, Gigabyte GTX460OC 768Mb
-
12th June 2011 20:46 #3Registered User
Join Date: Jun:2011
Location: Sofia
Posts: 3
? , . DOMDocument , , XML, DOM - . , .
-
12th June 2011 21:07 #4
,
PHP ,
XML-a ti .
saveXML()
XML. Self enclosed tags, custom print method.Free Your Mind!!!
-
12th June 2011 21:10 #5Registered User
Join Date: Jun:2011
Location: Sofia
Posts: 3
, php code XML-a . xml, , . , , , javascript.
-
15th June 2011 08:48 #6Registered User
Join Date: Jul:2005
Location: Sofiq
Posts: 2,798
javascript - JSON ? json_encode json_decode php.
-
15th June 2011 10:29 #7
spy_eye, :
DEVS (order by DEVS).
while, ( ), $node1 = $dom->createElement("DEVS"); node- ( ).




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in