hi very good
I'm trying to get the indices of the gallery that I have a xml file to display it in a <select>
xml file is as follows ..
I'm trying to use "foreach" but what brings me, is twice galleria, but that's fine, what happens is that it brings are the names, but I want indices, 0 and 1
xml file

<?xml version="1.0"?>
<content>
 <gallery Name="Hostal" Folder="Gallery/hostal">
 <image Thumb="thumb0.jpg" Large="0.jpg" Caption="Hostal Regina" Colour="181f0a">
	<comentarios><![CDATA[<p>Hostal Regina comentarios</p>]]></comentarios>
    </image>
    <image Thumb="thumb1.jpg" Large="1.jpg" Caption="Hostal Regina" Colour="181f0a">
	<comentarios><![CDATA[<p>Hostal Regina</p>]]></comentarios>
    </image>
  </gallery>
<gallery Name="Vistas" Folder="Gallery/nerja">
    <image Thumb="thumb0.jpg" Large="0.jpg" Caption="Vista Nocturna" Colour="eeeeeee">
	<comentarios><![CDATA[<p>Vista Nocturna realizada por Diego Palomo</p>]]></comentarios>
    </image>
<image Caption="eeeeeee"><comentarios>http://php-design-patterns.com</comentarios></image>
</gallery>
</content>

file select form

<select name="action">
<option value="">Escoger de la Lista</option>
<?php
$source = 'content.xml';
// load as string
$xmlstr = file_get_contents($source);
$sitemap = new SimpleXMLElement($xmlstr);
// load as file
$sitemap = new SimpleXMLElement($source,null,true);
foreach($sitemap->gallery as $index=>$content) {
$atributo = $content->attributes();
echo "<option value='".$index."'>".$index. "</option>";///in value no show index


}
?>
</select>

    I don't get it. Something like this?

    <?php $xml = simplexml_load_file('content.xml'); ?>
    
    <select name="action">
        <option value="">Escoger de la Lista</option>
    <?php foreach ($xml->gallery as $option) : ?>
        <option value="<?php echo $option->attributes()->Name; ?>"><?php echo $option->attributes()->Name; ?></option>
    <?php endforeach; ?>
    </select>

      hanks
      but so just get the names, but we the index, the index because then I need to edit the file, I need the index to indicate you want to edit gallery
      this is the code you need to get the index to its modification

      $index=1;
      $image = $sitemap->gallery[$index]->addChild('image');
      
      

        Then like this?

        <?php $xml = simplexml_load_file('qoobar.txt'); ?>
        
        <select name="action">
            <option value="">Escoger de la Lista</option>
        <?php for ($index = 0; $index < count($xml->gallery); $index++) : ?>
            <option value="<?php echo $index; ?>"><?php echo $xml->gallery[$index]->attributes()->Name; ?></option>
        <?php endfor; ?>
        </select>

          thank you very much, you were very friendly, so does the truth

            Write a Reply...