oracle765 Posted January 18, 2014 Share Posted January 18, 2014 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 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 18, 2014 Share Posted January 18, 2014 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. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted January 26, 2014 Author Share Posted January 26, 2014 thanks, do you do api work, I posted in the freelancer section Quote Link to comment Share on other sites More sharing options...
oracle765 Posted February 5, 2014 Author Share Posted February 5, 2014 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 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 5, 2014 Share Posted February 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
oracle765 Posted February 5, 2014 Author Share Posted February 5, 2014 Hi Mac_gyver Thanks so much that now gets the output in the attached file But somehow my for loop does not seem to present it nicely, any ideas Thanks output.txt Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted February 5, 2014 Solution Share Posted February 5, 2014 the resulting array contains 3222 numerically indexed sub-arrays of data. the foreach loop would be - foreach($json_arr as $arr){ // your code to reference the elements of $arr } Quote Link to comment Share on other sites More sharing options...
oracle765 Posted February 5, 2014 Author Share Posted February 5, 2014 that's brilliant that worked thankyou Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.