Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dynamic XML

New Here ,
Aug 29, 2009 Aug 29, 2009

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.
TOPICS
Server side applications
929
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 30, 2009 Aug 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);
?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 30, 2009 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2009 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2009 Aug 31, 2009

I loaded the php page into Firefox and I get the following message:

XML Parsing Error: no element found

Location: http://localhost/mottoth/user_ad_gallery.php

Line Number 4, Column 1:

^

I also loaded it into Safari and get a blank page, and in Opera and get the same message as in Firefox, what does this mean?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2009 Aug 31, 2009

It means that the XML isn't being created correctly. Right-click in the browser to view source and see what is being output by the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2009 Aug 31, 2009

Thanks for the quick response, the page source is:

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

I noticed on dreamweaver that in the code view <gallery> is colored red while </gallery> is light blue, I don't know if this means anything...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2009 Aug 31, 2009
LATEST

jt_10 wrote:

I noticed on dreamweaver that in the code view <gallery> is colored red while </gallery> is light blue, I don't know if this means anything...

Yes, it means that <gallery> is being treated as a PHP string. I have just copied and pasted everything into my version of Dreamweaver, and both <gallery> tags are in light blue. It sounds as though there's a mistake in your script somewhere.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines