Jump to content

XML, Spry, PHP, MySQL


bdmovies

Recommended Posts

I'm working on an app and am utilizing Adobe's Spry AJAX Library. The app is way to large to store in an XML database, I definitely need MySQL. But, in order to use Spry I need to convert the MySQL results into a XML file. I'll post what I've got, but I'm not sure how to get the results into a full XML file.

 

Also, several parts of my application are going to use XML - How do I go about creating the XML files and making sure the DB is caught up with the latest data or vice versa, keeping the XML file up to date....

 


<?php

require_once('../Connections/Connection.php');

$table_id = 'employees';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query);

// create a new XML document
$doc = new DomDocument('1.0');

// create root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);

// process one row at a time
while($row = mysql_fetch_assoc($dbresult)) {

  // add node for each row
  $occ = $doc->createElement($table_id);
  $occ = $root->appendChild($occ);
  
  // add a child node for each field
  foreach ($row as $fieldname => $fieldvalue) {
  
    $child = $doc->createElement($fieldname);
    $child = $occ->appendChild($child);

$value = $doc->createTextNode($fieldvalue);
    $value = $child->appendChild($value);

  } // foreach
} // while

// get completed xml document
$doc->saveXML();
?> 

Link to comment
https://forums.phpfreaks.com/topic/112296-xml-spry-php-mysql/
Share on other sites

you thinking more backwards than you should

 

XML should be updated to MySQL not MySQL updated to XML.

 

Your though process should be

 

Ajax request

mysql Update

Data Refresh

...Waiting time...

data refresh

...waiting...

data refresh

ajax request

etc.

 

 

make mysql be the keeper of all data and xml nibble on it for its needs.

Link to comment
https://forums.phpfreaks.com/topic/112296-xml-spry-php-mysql/#findComment-576559
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.