Hello guys,
I am new here and new to PHP and programming. I am working on a school project and asking for a little bit of help with simpleXML.
XML file named "menu.xml"
i have an XML file like this.
<?xml version="1.0" encoding="UTF-8"?>
<items>
<product>
<id>1</id>
<title> Tomato and cheese </title>
<pricelarge>20.00</pricelarge>
<pricesmall>10.00</pricesmall>
</product>
<product>
<id>2</id>
<title>Onions</title>
<pricelarge>8.99</pricelarge>
<pricesmall>3.99</pricesmall>
</product>
I can access the products via a function created with a foreach loop like this and output the information in a table.
function getmenu()
{
$menuout = '<table class ="menu">
<tr>';
foreach(get_xmlmenu() as $product)
{
$menuout .= '
<td class="menu">
<h4>'.$product->title.'</h4>
<div class ="pricelarge">
Large Size $'.$product->pricelarge.'
<a href="addtocart.php?id='.$product->id. "&price=".$product->pricelarge.'">Add to Cart</a>
</div>
<div class ="pricesmall">
Small Size $'.$product->pricesmall.'
<a href="addtocart.php?id='.$product->id. "&price=".$product->pricesmall.'">Add to Cart</a>
</div>
</td>';
}
$output .= '
</tr>
</table>';
return $menuout;
}
My question to the community is this.
I want my XML to be like this:
<xml>
<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>
<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>
</xml>
WHAT I NEED HELP with is How to have the Category Name show in a drop down menu and then once category is choosen the table to reflect with the items for that category.
Any help greatly appriciated. Willing to pay for solution.
Thank you very much!!
Tony