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