I am trying to call an image in my PHP to an XML file. I have tried to do this many different ways, but have not had much luck. More specifically, I am trying to call img file variable "Image1" to display. I have also sought tutoring, but the tutor was also somehow stumped on this, so any help is appreciated.
Prompt: (a) Create a XML file which contains the description of at least 3 product names, prices, and image file names.
(b) Load the XML file using Php and generate the shopping items: image, name, price and allow order quantity. Hint: Replace the image file names, item names, and prices with the Php codes. The Php codes supply the Php variables which were filled by reading the XML file at the beginning of the page. Then use "echo" verb to show the content of the session variable which contains the file name, item name, and price. The page should have the file extension .php.
//My XML
<?xml version="1.0" encoding="UTF-8"?>
<items>
<object>
<Name>CSU Womens T-Shirt</Name>
<Material>3% Polyester / 97% Cotton</Material>
<Price>$23.99</Price>
<image1>C:\Users\erica\OneDrive\Documents\IST450HW\IMGs\csupic.jpg</image1>
</object>
<object>
<Name>CSU Unisex Hat</Name>
<Material>2% Spandex / 98% Cotton</Material>
<Price>$10.99</Price>
</object>
<object>
<Name>CSU Men's T-Shirt</Name>
<Material>5% Polyester / 95% Cotton</Material>
<Price>$19.99</Price>
</object>
</items>
//My PHP
<?php
$xml = simplexml_load_file("Items.xml");
foreach ($xml as $key => $value) {
foreach ($value as $key => $value) {
echo $key.": ".$value."</br>";
}
}
$result = $xml->$items->$object->$image1;
echo '<img src="'.$result.'" height="100"; "width="100" ;>';
?>
foreach ($value as $key => $value)? - Tim Morton$value, so your outer loop is immediately trashed. I don't think you need$keyin the foreach, because you're iterating through the values (properties). There are no methods in a simplexml object. Take a look at stackoverflow.com/questions/4637617/… for how to iterate through the xml. - Tim Morton