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.

Re: PHP XML question

Just a quick glance at the XML file... Looks like you forgot to add closing </category> tags?

Re: PHP XML question

FalkenCreative,
My real XMl file looks like this and it does have the closing category tags. I have tested it in W3C validator and is a valid XML plus I can parse it to get the category name. The one a created here was just so you guys could get the picture. I think the problem is on my PHP. Thank you anyway.


<?xml version="1.0" encoding="utf-8" ?>
<menu>
<category name="Pizzas">
<item id="1">
<name>Tomato and Cheese</name>
<price>
<sm>5.50</sm>
<lg>9.75</lg>
</price>
</item>
<item id="2">
<name>Broccoli</name>
<price>
<sm>6.85</sm>
<lg>10.85</lg>
</price>
</item>
<item id="3">
<name>Onions</name>
<price>
<sm>6.85</sm>
<lg>10.85</lg>
</price>
</item>
<item id="4">
<name>Peppers</name>
<price>
<sm>6.85</sm>
<lg>10.85</lg>
</price>
</item>
</category>
<category name="Speciality Pizzas" sm="9.80" lg="15.80">
<item id="5">
<name>Mediterranean</name>
<description>Sliced Tomatoes, Olives, Spinach, Fresh Garlic, Mozzarella and Feta Cheese</description>
</item>
<item id="6">
<name>Vegetarian</name>
<description>Sliced Tomatoes, Onions, Peppers, Mushrooms, Broccoli and Mozzarella</description>
</item>
<item id="7">
<name>Faux BBQ Grilled Chicken</name>
<description>Choice Of Vegetables</description>
</item>
</category>
.......etc etc ect
........

Re: PHP XML question

One other quick thing to check... this line in your category.php file has a misspelling:

foreach ($cateogory->item as $item) <-- "category"

...doesn't look like that is necessarily connected to the issues you are having on your index page though.