Skip to main content
Participant
August 29, 2009
Question

Dynamic XML

  • August 29, 2009
  • 7 replies
  • 931 views

I have a image gallery extension that gets images from a folder through the following xml script:

<?xml version="1.0" encoding="utf-8"?>

<gallery>

     <item caption="Photo 01" image="images/image1.jpg" thumb_caption="caption 1" link="empty.html" target="_blank" />

     <item caption="Photo 02" image="images/image2.jpg" thumb_caption="caption 2" link="empty.html" target="_blank" />

     <item caption="Photo 03" image="images/image3.jpg" thumb_caption="caption 3" link="empty.html" target="_blank" />

     <item caption="Photo 04" image="images/image4.jpg" thumb_caption="caption 4" link="empty.html" target="_blank" />

     <item caption="Photo 05" image="images/image5.jpg" thumb_caption="caption 5" link="empty.html" target="_blank" />

     <item caption="Photo 06" image="images/image6.jpg" thumb_caption="caption 6" link="empty.html" target="_blank" />

</gallery>

I have been told by the suppliers of the extension that I can create a dynamic xml file (in my case with php) so that it retrieves the images from a database, but they haven't been much help in telling me how, but I found this page from Adobe Labs which shows how to do this but I might be doing something wrong because the extension doesn't identify the xml script, this is what my php file looks like:
<?php require_once('Connections/connUserInfo.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break; 
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$ID_var_rsUserGallery = "0";
if (isset($_GET['ID'])) {
  $ID_var_rsUserGallery = $_GET['ID'];
}
mysql_select_db($database_connUserInfo, $connUserInfo);
$query_rsUserGallery = sprintf("SELECT userinfo.ID, userinfo.image1, userinfo.image2, userinfo.image3, userinfo.image4, userinfo.image5, userinfo.image6 FROM userinfo WHERE userinfo.ID = %s", GetSQLValueString($ID_var_rsUserGallery, "int"));
$rsUserGallery = mysql_query($query_rsUserGallery, $connUserInfo) or die(mysql_error());
$row_rsUserGallery = mysql_fetch_assoc($rsUserGallery);
$totalRows_rsUserGallery = mysql_num_rows($rsUserGallery);
mysql_free_result($rsUserGallery);
// Send the headers
header('Content-type: text/xml');
header('Pragma: public');     
header('Cache-control: private');
header('Expires: -1');
?><?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<images>
  <?php if ($totalRows_rsUserGallery > 0) { // Show if recordset not empty ?>
  <?php do { ?>
<gallery>
     <item caption="Photo 01" image="<?php echo $row_rsUserGallery['image1']; ?>" thumb_caption="caption 1" link="empty.html" target="_blank" />
     <item caption="Photo 02" image="<?php echo $row_rsUserGallery['image2']; ?>" thumb_caption="caption 2" link="empty.html" target="_blank" />
     <item caption="Photo 03" image="<?php echo $row_rsUserGallery['image3']; ?>" thumb_caption="caption 3" link="empty.html" target="_blank" />
     <item caption="Photo 04" image="<?php echo $row_rsUserGallery['image4']; ?>" thumb_caption="caption 4" link="empty.html" target="_blank" />
     <item caption="Photo 05" image="<?php echo $row_rsUserGallery['image5']; ?>" thumb_caption="caption 5" link="empty.html" target="_blank" />
     <item caption="Photo 06" image="<?php echo $row_rsUserGallery['image6']; ?>" thumb_caption="caption 6" link="empty.html" target="_blank" />
</gallery>
    <?php } while ($row_rsUserGallery = mysql_fetch_assoc($rsUserGallery)); ?>
<?php } // Show if recordset not empty ?>
</images>
<?php
mysql_free_result($rsUserGallery);
?>
So I started experimenting with this script and noticed that if I remove the lines:
<images>
  <?php if ($totalRows_rsUserGallery > 0) { // Show if recordset not empty ?>
  <?php do { ?>
and
    <?php } while ($row_rsUserGallery = mysql_fetch_assoc($rsUserGallery)); ?>
<?php } // Show if recordset not empty ?>
</images>
the extension detects the xml script but still none of the images appear in the gallery.
So with the info that I've given, can anyone find anything wrong?
All help is greatly appreciated.
This topic has been closed for replies.

7 replies

David_Powers
Inspiring
August 30, 2009

There are two things wrong, your loop and the XML tags. The first part of your script, up to and including the header() section looks OK. Change the rest like this:

<?php echo('<?xml version="1.0" encoding="utf-8"?>');?>

<gallery>

  <?php if ($totalRows_rsUserGallery > 0) { // Show if recordset not empty ?>
     <item caption="Photo 01" image="<?php echo $row_rsUserGallery['image1']; ?>" thumb_caption="caption 1" link="empty.html" target="_blank" />
     <item caption="Photo 02" image="<?php echo $row_rsUserGallery['image2']; ?>" thumb_caption="caption 2" link="empty.html" target="_blank" />
     <item caption="Photo 03" image="<?php echo $row_rsUserGallery['image3']; ?>" thumb_caption="caption 3" link="empty.html" target="_blank" />
     <item caption="Photo 04" image="<?php echo $row_rsUserGallery['image4']; ?>" thumb_caption="caption 4" link="empty.html" target="_blank" />
     <item caption="Photo 05" image="<?php echo $row_rsUserGallery['image5']; ?>" thumb_caption="caption 5" link="empty.html" target="_blank" />
     <item caption="Photo 06" image="<?php echo $row_rsUserGallery['image6']; ?>" thumb_caption="caption 6" link="empty.html" target="_blank" />
</gallery>
<?php } // Show if recordset not empty ?>

<?php
mysql_free_result($rsUserGallery);
?>
jt_10Author
Participant
August 30, 2009

Thanks for the response, that cleared some things up but it seems like the extension still can't recognize the xml script, what I mean is that when the extension recognizes the script, the thumbnails show their cation titles ( ex: Caption 1, Caption 2, ect.) but when the extension doesn't recognize the xml script, the gallery appears but none of the image appear and the thumbnails don't display their corresponding captions. Has anyone used the image galleries from flashdevelopment24.com to do this? and what else could I try?

Thanks again.

David_Powers
Inspiring
August 31, 2009

I can't help you with the extension, but the first thing you need to check is that the PHP page is outputting the correct XML. Just load the PHP page into a browser, and see what it produces.