0

OK, I have a simple xml call which retrieves data via an api, please see code below:

      $file = 'http://mywebsite.com/computers.xml?apikey=88888&cid=api&limit=5&page=1 '     ;
      if(!$xml = simplexml_load_file($file))
      exit('Failed to open '.$file); 

      $total_pages = $xml->results->attributes()->totalPages;
      $current_page = $xml->results->attributes()->currentPage;
      $total_results = $xml->results->attributes()->totalResults;

      foreach($xml->computer as $computer){
  echo $computer['name'];

this all works perfect and breaks down the total number of pages, results and current page. With an if else statement i can generate next and previous buttons, however if i include the link to the api, when i click on it it simply calls the page and show the results as an xml format.

When what i want to achieve is yo provide a button which simply calls the second page of these results, i.e

      $file = 'http://mywebsite.com/computers.xml?apikey=88888&cid=api&limit=5&page=2

however just clicking on this link shows the page in xml format, so what i need to do is to click on a button and retrieve the info via the simple xml function, however i do not know if this is possible or how to go about it.

And so any advice would be appreciated.

Thanks

Stan Williams
  • 263
  • 3
  • 14
  • you mean you want to have the server make a request so you can parse it and display prettier results? http://stackoverflow.com/questions/2001897/get-the-value-of-an-url-response-with-curl – FlavorScape Nov 08 '12 at 17:59
  • It is very unclear by this question what you actually want to happen. Please edit the questions text and add information about: what exactly should happen, what is your current implementation and ehat exactly is not working as expected. You waste peoples time by just telling a few words and expecting them to guess what you might want to happen. – arkascha Nov 08 '12 at 18:02

1 Answers1

0

You need to render a button that links to it's own url, plus a query parameter.

// get the param
$pageNum = $_GET['page'];
// modify your api call query string
$file = '...8888&cid=api&limit=5&page=' . $pageNum;   

then your next button would link to

...href='ownpage.php?page=' . &pageNum + 1 

and prev

...href='ownpage.php?page=' . &pageNum - 1 

and I suppose your default page in the case where the page parameter is not supplied, you would default $pageNum to 1.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117