$aid= $_GET["aid"];
echo $xml->orders->ITEM["$aid"]->name;
With this script I'm trying to display the value of an XML page. The variable $aid
is the number of elements. This can be 0 to 1000.
Only nothing displays when I run this script.
This works fine
$aid= $_GET["aid"];
echo $xml->orders->ITEM[1]->name;
You're assigning the key wrong, use just the variable name without the apostrophes.
echo $xml->orders->ITEM[$aid]->name;
Use an integer key, values from $_GET
are strings.
$aid = (int) $_GET["aid"];
echo $xml->orders->ITEM[$aid]->name;
With SimpleXML, integer values denote an element in a collection (e.g. 0
is the first, 1
is the second) whereas string values denote attributes of that name.
I'm assuming the value isn't just a number (since SimpleXML can recognise that, even as a string).