Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <code>SimpleXML</code> object (or its properties) in a <code>foreach</code> loop. If you want to loop through all the 'records' something like this can be used to access and display the data:</p> <pre><code>//Loop through all the members of the Item array //(essentially your two database rows). foreach($SimpleXML-&gt;body-&gt;QueryWithAttributesResult-&gt;Item as $Item){ //Now you can access the 'row' data using $Item in this case //two elements, a name and an array of key/value pairs echo $Item-&gt;Name; //Loop through the attribute array to access the 'fields'. foreach($Item-&gt;Attribute as $Attribute){ //Each attribute has two elements, name and value. echo $Attribute-&gt;Name . ": " . $Attribute-&gt;Value; } } </code></pre> <p>Note that $Item will be a SimpleXML object, as is $Attribute, so they need to be referenced as objects, not arrays. </p> <p>While the example code above is looping through the arrays in the SimpleXML object ($SimpleXML->body->QueryWithAttributesResult->Item), you can also loop through a SimpleXML object (say $SimpleXML->body->QueryWithAttributesResult->Item[0]), and that would give you each of the object's properties.</p> <p>Each child element of a SimpleXML object is an XML entity. If the XML entity (tag) is not unique, then the element is simply an array of SimpleXML objects representing each entity.</p> <p>If you want, this should create a more common row/fields array from your SimpleXML object (or get you close):</p> <pre><code>foreach($SimpleXML-&gt;body-&gt;QueryWithAttributesResult-&gt;Item as $Item){ foreach($Item-&gt;Attribute as $Attribute){ $rows[$Item-&gt;Name][$Attribute-&gt;Name] = $Attribute-&gt;Value; } } //Now you have an array that looks like: $rows['message12413344443260']['active'] = 1; $rows['message12413344443260']['user'] = 'john'; //etc. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload