rfeio Posted January 14, 2009 Share Posted January 14, 2009 Hi, I have the following XML: <NewDataSet> <TransactionList> <TransactionID>272201222</TransactionID> <TransactionDate>2008-12-31T11:05:00+00:00</TransactionDate> <SaleValue>3.3900</SaleValue> </TransactionList> <TransactionList> <TransactionID>274879519</TransactionID> <TransactionDate>2009-01-13T14:40:00+00:00</TransactionDate> <SaleValue>19.9900</SaleValue> </TransactionList> </NewDataSet> I would now like to create an array with this info. For that I have come up with the following code: $count = count($xml -> TransactionList); echo '<br><br>Total records = '.$count; for($i=0; $i < $count; $i++) { $transaction_id[$i] = $xml -> TransactionList -> TransactionID; $transaction_date[$i] = $xml -> TransactionList -> TransactionDate; $sale[$i] = $xml -> TransactionList -> SaleValue; } The problem is that the array always gets the data from the first record. When I print the array I get: Total records = 2 Record #1: Transaction id= 272201222 Transaction date= 2008-12-31T11:05:00+00:00 Sale= 3.3900 Record #2: Transaction id= 272201222 Transaction date= 2008-12-31T11:05:00+00:00 Sale= 3.3900 What am I missing? How can I load all the records on the XML to the array? Cheers! Link to comment https://forums.phpfreaks.com/topic/140794-xml-parse-issue/ Share on other sites More sharing options...
rfeio Posted January 14, 2009 Author Share Posted January 14, 2009 The solution is to do: $xml -> TransactionList[$i] -> TransactionID; Link to comment https://forums.phpfreaks.com/topic/140794-xml-parse-issue/#findComment-736927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.