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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.