Jump to content

How can API query be presented nicely on results page


oracle765
Go to solution Solved by mac_gyver,

Recommended Posts

Hi Professional

 

I have a webpage like called testrest.php attached which pulls in results from an api query, it is very basic

 

 

the problem is it pulls on many many results in a format I am not sure how to present on a results page.

 

Is there a way to get around this

 

please see webpage and results out put

 

thanks

testrest.php

API Results.txt

Link to comment
Share on other sites

you can do anything you want with the data (that's the point of programming, to get a general purpose computer to do what you want.)

 

you can loop through the repeated data by using (untested) -

foreach($json_arr['HotelListResponse']['HotelList']['HotelSummary'] as $arr){

    // $arr will be an array of each hotel's data

}

the elements of the $arr array inside the above loop would be referenced like -  $arr['name'], $arr['city'], ... you could either hard code the references or you could make an array of the element names, then just loop over that defining array and dynamically reference those element in the $arr array.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

ok I have tried to make this more simple for clarity sake, I am downloading a straightforward json file.

 

when I put the url into the browser it prompts me to open or save the file which is fine

 

when I run the php file I try to do the same and output the data to screen but trouble is it is blank

 

am I missing something here is the very basic page

appliancesnow.php

Link to comment
Share on other sites

your url contains some $, which when inside a double-quoted string are treated as php variables.

 

you need to have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting all the errors it detects.

 

you can correct the current problem by switching to single-quotes around the url string.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.