rahulpatel
Programmer
Not sure if this is a PHP question or a XML question, so I'll ask it here first.
I have a database in mysql and I am making a gallery from it. I found a 'flash' gallery that works from a xml file. I don't want to keep amending my files as and when I add an image, so I'm trying to make it dynamic. I have had success up to a point.
This is what the original file looks like
This is what I have got to, to try and make the gallery.xml dynamic...
My code works well apart from the code that tells the flash gallery how many columns there are, borders etc. I cannot find out how to get it in. Any spaces in the createElement line throws an error. I need to add these instructions to the root element
maxImageWidth="400" maxImageHeight="400" imageFit="normal" textColor="0x009999" frameColor="0x000000" frameWidth="5" stagePadding="10" thumbnailColumns="2" thumbnailRows="4" navPosition="right" imagePath="images/" thumbPath="images/thumbs/" autoPlay="false" slideInterval="5" imageDefaultLink="self"
Does anyone know how to solve this issue. The root element is not dynamic but I can't hard code it either. Any help is always gratefully received.
I have a database in mysql and I am making a gallery from it. I found a 'flash' gallery that works from a xml file. I don't want to keep amending my files as and when I add an image, so I'm trying to make it dynamic. I have had success up to a point.
This is what the original file looks like
Code:
<?xml version="1.0" encoding="UTF-8"?>
<veppaPhotoAlbum maxImageWidth="400" maxImageHeight="400" imageFit="normal" textColor="0x009999" frameColor="0x000000" frameWidth="5" stagePadding="10" thumbnailColumns="2" thumbnailRows="4" navPosition="right" imagePath="images/" thumbPath="images/thumbs/" autoPlay="false" slideInterval="5" imageDefaultLink="self">
<image>
<filename>....
This is what I have got to, to try and make the gallery.xml dynamic...
Code:
<?php
if(!$dbconnect = mysql_connect('localhost', 'root', '')) {
echo "Connection failed to the host 'localhost'.";
exit;
} // if
if (!mysql_select_db('gallery')) {
echo "Cannot connect to database 'gallery'";
exit;
} // if
$table_id = 'image';
$query = "SELECT filename, caption FROM image";
$dbresult = mysql_query($query, $dbconnect);
// create a new XML document
$doc = new DomDocument('1.0');
$doc->encoding="UTF-8";
// create root node
$root = $doc->createElement('veppaPhotoAlbum');
$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
$xml_string = $doc->saveXML();
echo $xml_string;
print $doc->save("gallery.xml");
?>
My code works well apart from the code that tells the flash gallery how many columns there are, borders etc. I cannot find out how to get it in. Any spaces in the createElement line throws an error. I need to add these instructions to the root element
maxImageWidth="400" maxImageHeight="400" imageFit="normal" textColor="0x009999" frameColor="0x000000" frameWidth="5" stagePadding="10" thumbnailColumns="2" thumbnailRows="4" navPosition="right" imagePath="images/" thumbPath="images/thumbs/" autoPlay="false" slideInterval="5" imageDefaultLink="self"
Does anyone know how to solve this issue. The root element is not dynamic but I can't hard code it either. Any help is always gratefully received.