Cooper94 Posted December 20, 2009 Share Posted December 20, 2009 <?php $dom = new DOMDocument("1.0"); header("Content-Type: text/plain"); $root = $dom->createElement("flights"); $dom->appendChild($root); $item = $dom->createElement("Departure"); $root->appendChild($item); $text = $dom->createTextNode("KLGA"); $item->appendChild($text); $item = $dom->createElement("Arrival"); $root->appendChild($item); $text = $dom->createTextNode("KPHL"); $item->appendChild($text); $item = $dom->createElement("Aircraft"); $root->appendChild($item); $text = $dom->createTextNode("E170"); $item->appendChild($text); echo $dom->saveXML(); ?> Is there anyway to create more than one element? Like say I want another element named Flights but just with different information in the nodes with that be possible? Thank you all for your time! Quote Link to comment Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Sure, just run a foreach loop on however many flights you have. Not sure what your data structure is like, but a simple loop should do the trick. Quote Link to comment Share on other sites More sharing options...
Cooper94 Posted December 20, 2009 Author Share Posted December 20, 2009 Ok is there anyway you could help me with this? I am grabing this information from a database and so far I only have this. I thank you again for all the help! <?php include '../includes/db.php'; $result = mysql_query("SELECT * FROM reports WHERE callsign = '$_GET[pilot]' AND status = '0'"); while ($row = mysql_fetch_array($result)) { } $dom = new DOMDocument("1.0"); header("Content-Type: text/plain"); $root = $dom->createElement("flights"); $dom->appendChild($root); $item = $dom->createElement("Departure"); $root->appendChild($item); $text = $dom->createTextNode("KLGA"); $item->appendChild($text); $item = $dom->createElement("Arrival"); $root->appendChild($item); $text = $dom->createTextNode("KPHL"); $item->appendChild($text); $item = $dom->createElement("Aircraft"); $root->appendChild($item); $text = $dom->createTextNode("E170"); $item->appendChild($text); echo $dom->saveXML(); ?> Quote Link to comment Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Sure The steps you want to take are #1 - Retrieve your info from the database, and store the results in an array. Change <?php // Not sure what you were trying to do here...gotta do something in the loop while ($row = mysql_fetch_array($result)) { } ?> To while ($row = mysql_fetch_array($result)) { $data[] = $row; } Now that we have all of your data in an array, you can then more on to the XML portion. // I've never used this particular extension..if this doesn't work I'll look into it a bit more. <?php foreach ($data as $flights){ $root = $dom->createElement("flights"); $dom->appendChild($root); $item = $dom->createElement("Departure"); $root->appendChild($item); $text = $dom->createTextNode($flight['departure']); $item->appendChild($text); $item = $dom->createElement("Arrival"); $root->appendChild($item); $text = $dom->createTextNode($flight['arrival']; $item->appendChild($text); $item = $dom->createElement("Aircraft"); $root->appendChild($item); $text = $dom->createTextNode($flight['aircraft']); $item->appendChild($text); endforeach;?> Quote Link to comment Share on other sites More sharing options...
Cooper94 Posted December 20, 2009 Author Share Posted December 20, 2009 I did as asked and I get a 500 Internal Server Error... Any thoughts and I really do thank you once again for all of this help!!!! Quote Link to comment Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Hrmn. Before the foreach loop, put the following <?php // Put this after you the $data array is made var_dump($data); die(); ?> What I want to see is #1) If the database connection is working properly #2) What the data is Quote Link to comment Share on other sites More sharing options...
Cooper94 Posted December 20, 2009 Author Share Posted December 20, 2009 Lol its alot but I went through it and it is all right! Thank you array(2) { [0]=> array(40) { [0]=> string(2) "15" ["id"]=> string(2) "15" [1]=> string(0) "" ["date"]=> string(0) "" [2]=> string(7) "RPA1001" ["callsign"]=> string(7) "RPA1001" [3]=> string(7) "RPA3265" ["flight_num"]=> string(7) "RPA3265" [4]=> string(4) "E170" ["aircraft"]=> string(4) "E170" [5]=> string(0) "" ["online"]=> string(0) "" [6]=> string(0) "" ["duration"]=> string(0) "" [7]=> string(4) "KPHL" ["pilot_hub"]=> string(4) "KPHL" [8]=> string(0) "" ["fuel_used"]=> string(0) "" [9]=> string(0) "" ["pax"]=> string(0) "" [10]=> string(0) "" ["money"]=> string(0) "" [11]=> string(0) "" ["rate"]=> string(0) "" [12]=> string(0) "" ["method"]=> string(0) "" [13]=> string(4) "KALB" ["dep_icao"]=> string(4) "KALB" [14]=> string(0) "" ["dep_time"]=> string(0) "" [15]=> string(4) "KCLT" ["arr_icao"]=> string(4) "KCLT" [16]=> string(0) "" ["arr_time"]=> string(0) "" [17]=> string(26) "PWL CMK J75 GVE LYH SUDSY3" ["route"]=> string(26) "PWL CMK J75 GVE LYH SUDSY3" [18]=> string(1) "0" ["status"]=> string(1) "0" [19]=> string(0) "" ["comments"]=> string(0) "" } [1]=> array(40) { [0]=> string(2) "14" ["id"]=> string(2) "14" [1]=> string(0) "" ["date"]=> string(0) "" [2]=> string(7) "RPA1001" ["callsign"]=> string(7) "RPA1001" [3]=> string(7) "RPA3049" ["flight_num"]=> string(7) "RPA3049" [4]=> string(4) "E145" ["aircraft"]=> string(4) "E145" [5]=> string(0) "" ["online"]=> string(0) "" [6]=> string(0) "" ["duration"]=> string(0) "" [7]=> string(4) "KPHL" ["pilot_hub"]=> string(4) "KPHL" [8]=> string(0) "" ["fuel_used"]=> string(0) "" [9]=> string(0) "" ["pax"]=> string(0) "" [10]=> string(0) "" ["money"]=> string(0) "" [11]=> string(0) "" ["rate"]=> string(0) "" [12]=> string(0) "" ["method"]=> string(0) "" [13]=> string(4) "KCLT" ["dep_icao"]=> string(4) "KCLT" [14]=> string(0) "" ["dep_time"]=> string(0) "" [15]=> string(4) "KSDF" ["arr_icao"]=> string(4) "KSDF" [16]=> string(0) "" ["arr_time"]=> string(0) "" [17]=> string(0) "" ["route"]=> string(0) "" [18]=> string(1) "0" ["status"]=> string(1) "0" [19]=> string(0) "" ["comments"]=> string(0) "" } } Quote Link to comment Share on other sites More sharing options...
Cooper94 Posted December 20, 2009 Author Share Posted December 20, 2009 Ok I got it to display something but it dosnt display all of it, it gives me this error: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. Only one top level element is allowed in an XML document. Error processing resource 'http://www.purified-designs.com/V2/aca... <flights><Departure></Departure><Arrival>KSDF</Arrival><Aircraft>E145</Aircraft>&l... Here is the code!Thank you! <?php include '../includes/db.php'; $result = mysql_query("SELECT * FROM reports WHERE callsign = '$_GET[pilot]' AND status = '0'"); $num = mysql_num_rows($result); while ($row = mysql_fetch_array($result)){ $data[] = $row; } $dom = new DOMDocument("1.0"); header("Content-Type: text/plain"); foreach ($data as $flights){ $root = $dom->createElement("flights"); $dom->appendChild($root); $item = $dom->createElement("Departure"); $root->appendChild($item); $text = $dom->createTextNode($flight['dep_icao']); $item->appendChild($text); $item = $dom->createElement("Arrival"); $root->appendChild($item); $text = $dom->createTextNode($flights['arr_icao']); $item->appendChild($text); $item = $dom->createElement("Aircraft"); $root->appendChild($item); $text = $dom->createTextNode($flights['aircraft']); $item->appendChild($text); } echo $dom->saveXML(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.