christsealed
New member
Hi,
I'm working on a Flash image gallery that parses an XML file in order to retrieve its image data. Below is the PHP that creates the XML.
I’m creating a UNION of two tables that hold the information Flash needs to parse. In my select statement, I’m limiting MySQL to return only results WHERE the galleryTitle is the same as the folder. In that way, I’m able to return only galleries that have images in them, since the folders will hold the images. I’m also aware that for production purposes, this means the galleryTitle will HAVE to be the same as the folder, but I’m fine with that, as I intend to write a function that automates the folder creation process.
<?PHP
$link = mysql_connect ("localhost", "root", "");
mysql_select_db ("test");
$query = 'SELECT galleries.*, images.folder, images.imgName, images.imgDescription FROM galleries, images WHERE galleryTitle = folder';
$results = mysql_query($query);
echo "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
echo "<galleries>\n";
while ($line = mysql_fetch_assoc($results)) {
echo "<gallery title=\"{$line["galleryTitle"]}\" intro=\"{$line["galleryIntro"]}\">\n";
$i=0;
if (count($line["imgName"])>$i) {
$i++;
echo "<img src=\"{$line["folder"]}/{$line["imgName"]}\" description=\"{$line["imgDescription"]}\" />\n";
}
echo "</gallery>\n";
}
echo "</galleries>";
mysql_close($link);
?>
So far, this works perfectly. And in truth, I don’t even really need the “for” loop, as it was part of a failed experiment to see if it could help me order my results in the format that I wanted, which is below.
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>
<galleries>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/1.jpg" description="Description 1" />
<img src="architecture/2.jpg" description="Description 2" />
<img src="architecture/3.jpg" description="Description 3" />
<img src="architecture/4.jpg" description="Description 4" />
<img src="architecture/5.jpg" description="Description 5" />
</gallery>
</galleries>
However, with or without the “for” loop, what I get is this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<galleries>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/1.jpg" description="Description 1" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/2.jpg" description="Description 2" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/3.jpg" description="Description 3" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/4.jpg" description="Description 4" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/5.jpg" description="Description 5" />
</gallery>
</galleries>
I’ve tried grouping the galleryTitle row using the GROUP BY relational operator in the SQL statement. However, that only returns one result for the images, while I have more than that.
ORDER BY is not an option, since it only alphabetizes the results, and doesn’t eliminate any redundancies.
What should I do?
I'm working on a Flash image gallery that parses an XML file in order to retrieve its image data. Below is the PHP that creates the XML.
I’m creating a UNION of two tables that hold the information Flash needs to parse. In my select statement, I’m limiting MySQL to return only results WHERE the galleryTitle is the same as the folder. In that way, I’m able to return only galleries that have images in them, since the folders will hold the images. I’m also aware that for production purposes, this means the galleryTitle will HAVE to be the same as the folder, but I’m fine with that, as I intend to write a function that automates the folder creation process.
<?PHP
$link = mysql_connect ("localhost", "root", "");
mysql_select_db ("test");
$query = 'SELECT galleries.*, images.folder, images.imgName, images.imgDescription FROM galleries, images WHERE galleryTitle = folder';
$results = mysql_query($query);
echo "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
echo "<galleries>\n";
while ($line = mysql_fetch_assoc($results)) {
echo "<gallery title=\"{$line["galleryTitle"]}\" intro=\"{$line["galleryIntro"]}\">\n";
$i=0;
if (count($line["imgName"])>$i) {
$i++;
echo "<img src=\"{$line["folder"]}/{$line["imgName"]}\" description=\"{$line["imgDescription"]}\" />\n";
}
echo "</gallery>\n";
}
echo "</galleries>";
mysql_close($link);
?>
So far, this works perfectly. And in truth, I don’t even really need the “for” loop, as it was part of a failed experiment to see if it could help me order my results in the format that I wanted, which is below.
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>
<galleries>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/1.jpg" description="Description 1" />
<img src="architecture/2.jpg" description="Description 2" />
<img src="architecture/3.jpg" description="Description 3" />
<img src="architecture/4.jpg" description="Description 4" />
<img src="architecture/5.jpg" description="Description 5" />
</gallery>
</galleries>
However, with or without the “for” loop, what I get is this:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<galleries>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/1.jpg" description="Description 1" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/2.jpg" description="Description 2" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/3.jpg" description="Description 3" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/4.jpg" description="Description 4" />
</gallery>
<gallery title="architecture" intro="These are the photos of various buildings in the cities I visited .">
<img src="architecture/5.jpg" description="Description 5" />
</gallery>
</galleries>
I’ve tried grouping the galleryTitle row using the GROUP BY relational operator in the SQL statement. However, that only returns one result for the images, while I have more than that.
ORDER BY is not an option, since it only alphabetizes the results, and doesn’t eliminate any redundancies.
What should I do?