Jump to content

Array into Dropdown list


mcfmullen

Recommended Posts

Alright, so I have an xml file differences.xml that is being parsed in XML. This is what the xml looks like:

 

<item  code="lM" name="dog">
<cost>5000</cost>
<Start>12/15/2010</Start>
<End>01/13/2011</End>
</item>
<item  code="lF" name="cat">
<cost>5000</cost>
<Start>04/15/2010</Start>
<End>04/23/2011</End>
</item>[/

 

I want to have the item names (dog, cat) show in a dropdown menu so that I can select these items for editing before storing in my mysql database.

 

This is the php code I have so far:

<?PHP

$xml = simplexml_load_file("differences.xml");

$object = $xml->xpath("//item");

echo '<SELECT name=object>';

foreach ($object['name'] as $key => $value)

{

echo '<OPTION value='.$value.'> '.$value;

}

echo '</select>';
?>

 

I do have a dropdown list but there are no values inside it (it is empty). Can anyone help me figure out why?

 

I do have this code that does work which lists the items in plaintext (not in a dropdown) so hopefull this will help us out:

 

<?PHP

$xml = simplexml_load_file("differences.xml");

$object = $xml->xpath("//item");

$count = count($object);

$i = 0;

while($i < $count)
{

echo '<h1>'.$object[$i]['name'].'</h1>';

$i++;

}


?>

 

Link to comment
https://forums.phpfreaks.com/topic/222156-array-into-dropdown-list/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.