0

I am working with the lastfm api and i want to be able to paginate the search results from the artist search.

<results xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" for="cher">
<opensearch:Query role="request" searchTerms="cher" startPage="1"/>
<opensearch:totalResults>1302</opensearch:totalResults>
<opensearch:startIndex>0</opensearch:startIndex>
<opensearch:itemsPerPage>30</opensearch:itemsPerPage>

I would guess that it would involve taking the totalresults node and dividing it by the items per page. but how do i get the info from totalresults using php?

if this $artists = $xml->results->artistmatches->artist; is how i get the artists, how do i get the correct opensearch node totalresults and items per page?

Danny Connolly
  • 879
  • 3
  • 10
  • 27

1 Answers1

0

Assuming you use simpleXML:

$total = (int) $xml->results->children("http://a9.com/-/spec/opensearch/1.1/")->totalResults
jkovacs
  • 3,470
  • 1
  • 23
  • 24