Topic: PHP XML question
I have an XML like this.
<menu>
<category name="Fruit">
<item id="1">
<name>Apple</name>
<price>
<sm>5.50</sm>
<lg>9.75</lg>
</price>
</item>
<category name="Desert">
<item id="23">
<name>Ice Cream</name>
<price>7.35</price>
</item>
<menu>
My index.php looks like this and it gives me the drop down box and displays only the name of the first category.
<?php
$xml_file = file_get_contents("testmenu.xml");
$xml = simplexml_load_string($xml_file);
echo '<form name="products" action="category.php" method="post">';
echo '<select>';
foreach ($xml->category as $category)
{
echo "<option> ".$category['name']."</option>";
}
echo '</select>';
echo '</form>';
?>
My Category.php looks like this and it Doesn't WORK.
<?php
$category = $_Post['products']
$xml_file = file_get_contents("testmenu.xml");
foreach ($cateogory->item as $item)
{
echo $item['name'];
}
?>
Where is my mistake? any thoughts? I have been looking all over trying to find a solution for 5 days now. Any help will be greatly appriciated.
