Hello, Im a beginner to intermediate developer who just got the Sitepoint book and is working on some of my own projects at the same time. I’ve got a small issue and wondering if anyone can help me.
I’'ve got an xml file with galleries objects for different days - Thus, Fri etc …
I’m trying to create a PHP script which pulls ONLY the gallerylinks from when Thursday
Here is what I’ve been trying, BUT It still seems to pull in ALL the images from ALL the days …
PHP script
<?
$doc = new DOMDocument();
$doc->load( '../xml/galleries.xml' );
$galleries = $doc->getElementsByTagName( "gallery" );
$gallerydays = $doc->getElementsByTagName( "day" );
foreach( $gallerydays as $galleryday )
{
$days = $galleryday->getElementsByTagName( "day" );
$day = $days->item(0)->nodeValue;
If ($day = 'Thursday') {
foreach( $galleries as $gallery )
{
$titles = $gallery->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
$images = $gallery->getElementsByTagName( "galleryImage" );
$image = $images->item(0)->nodeValue;
echo "<tr>";
echo "<td valign='top'><img src='$galleryImage' alt='$galleryImage' width='100' /></td>";
echo "<td><p><strong>$title</strong><br />$image</p><p>$description</p></td>";
echo "</tr>";
}
}
}
?>
and the xml source file is …
<?xml version="1.0" encoding="UTF-8"?>
<galleries>
<!--THURSDAY GALLERIES -->
<gallery>
<day>Thursday</day>
<galleryLink>http://sample.php</galleryLink>
<title>Test Gallery One</title>
<galleryImage>http://www.hl.com/northamerica/sp/images/latin_Ext001.jpg</galleryImage>
</gallery>
<gallery>
<day>Thursday</day>
<galleryLink>http://http://sample.php</galleryLink>
<title>Test Gallery One</title>
<galleryImage>http://www.hl.com/northamerica/sp/images/latin_Ext002.jpg</galleryImage>
</gallery>
<!--FRIDAY GALLERIES -->
<gallery>
<galleryLink>http://sample.php</galleryLink>
<title>Test Gallery Two</title>
<galleryImage>http://www.hl.com/northamerica/sp/images/latin_Ext011.jpg</galleryImage>
<day>Friday</day>
</gallery>
Thank you in advance for your help.