Hi Everyone .. As usual I need some simple help. I promise when I'm done with this very lengthy project I'll be the helper instead of the "helped".
Here is my issue:
I have XML identical to the following being posted to my PHP page. I'm picking it up with no problem:
<PhoneData>
<Phone>
<PhoneID>21</PhoneID>
<ServiceType>TDMA </ServiceType>
<ManufacturerID>6</ManufacturerID>
<ModelID>179</ModelID>
<Price>70.00</Price>
</Phone>
<Phone>
<PhoneID>148</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>6</ManufacturerID>
<ModelID>396</ModelID>
<Price>70.00</Price>
</Phone>
<Phone>
<PhoneID>149</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>178</ManufacturerID>
<ModelID>397</ModelID>
<Price>90.00</Price>
</Phone>
<Phone>
<PhoneID>150</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>8</ManufacturerID>
<ModelID>398</ModelID>
<Price>125.00</Price>
</Phone>
<Phone>
<PhoneID>151</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>8</ManufacturerID>
<ModelID>399</ModelID>
<Price>195.00</Price>
</Phone>
<Phone>
<PhoneID>162</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>8</ManufacturerID>
<ModelID>407</ModelID>
<Price>275.00</Price>
</Phone>
<Phone>
<PhoneID>155</PhoneID>
<ServiceType>GSM </ServiceType>
<ManufacturerID>104</ManufacturerID>
<ModelID>412</ModelID>
<Price>57.00</Price>
</Phone>
</PhoneData>
Once I get this data I'm using the following XML parser to go through it and store info into it's respective variables, this is working:
<?
function GetElementByName ($xml, $start, $end) {
global $pos;
$startpos = strpos($xml, $start);
if ($startpos === false) {
return false;
}
$endpos = strpos($xml, $end);
$endpos = $endpos+strlen($end);
$pos = $endpos;
$endpos = $endpos-$startpos;
$endpos = $endpos - strlen($end);
$tag = substr ($xml, $startpos, $endpos);
$tag = substr ($tag, strlen($start));
return $tag;
}
// Open and read XML data supplied by $HTTP_RAW_POST_DATA
$data = "$thexmlabove";
$pos = 0;
$Nodes = array();
$data = $data . $getline;
$count = 0;
$pos = 0;
// Here we specify the starting and end closing tags
// Goes through XML file and creates an array of all <XML_TAG> tags.
while ($node = GetElementByName($data, "<PhoneData>", "</PhoneData>")) {
$Nodes[$count] = $node;
$count++;
$data = substr($data, $pos);
}
// Gets infomation from child tags.
for ($i=0; $i<$count; $i++) {
$ServiceType = GetElementByName($Nodes[$i], "<ServiceType>", "</ServiceType>");
$Manufacturer = GetElementByName($Nodes[$i], "<ManufacturerID>", "</ManufacturerID>");
$DeviceType = GetElementByName($Nodes[$i], "<ModelID>", "</ModelID>");
$Price = GetElementByName($Nodes[$i], "<Price>", "</Price>");
$PhoneID = GetElementByName($Nodes[$i], "<PhoneID>", "</PhoneID>");
$ServiceType = GetElementByName($Nodes[$i], "<ServiceType>", "</ServiceType>");
$Manufacturer = GetElementByName($Nodes[$i], "<ManufacturerID>", "</ManufacturerID>");
$DeviceType = GetElementByName($Nodes[$i], "<ModelID>", "</ModelID>");
$Price = GetElementByName($Nodes[$i], "<Price>", "</Price>");
?>
My problem is here:
As you can see in the XML everything shows up more than once (there is more than one phone model) so, <Price> </Price> is there for each phone, <PhoneID> </PhoneID> is there for each phone and so on . .
When I echo $PhoneID I get the first one .. 21
But how do I access the second(148), third(149) and so on?
Note: I tried something like echo $PhoneID[1] & echo $PhoneID[2] with no luck. . . please help.