joewilson Posted November 13, 2013 Share Posted November 13, 2013 Hi I am writing this code for a wordpress plugin that gets content from a json file and then decodes them <table border="1"> <tr> <th>Thumbnail</th> <th>Title</th> <th>Excerpt</th> </tr> <?php $url = http://localhost/wordpress/json; $json = file_get_contents($url); $safe_json = str_replace("\n", "\\n", $json); $query = json_decode($json, true); foreach ( $query as $item ) { echo '<tr>'; echo '<td>' . $item['image'] .'</td>'; echo '<td>' . $item['title'] .'</td>'; echo '<td>' . $item['excerpt'] .'</td>'; echo '</tr>'; } ?> Now I need help in paginating the data. Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/283875-json-decode-and-get-file-content/ Share on other sites More sharing options...
dalecosp Posted November 13, 2013 Share Posted November 13, 2013 Well, if you're planning to paginate, you probably shouldn't be calling "echo" on the data; create an array to hold it and push it though a loop (or use a template).That said, how much data are we talking about? If you're really using multiple pages (that is, a new page load for each page), wouldn't it be preferable to have your data resource only return enough data to create one page, and then get the data for the next page on the next page load?Or are we talking about AJAX-type paging here? Quote Link to comment https://forums.phpfreaks.com/topic/283875-json-decode-and-get-file-content/#findComment-1458167 Share on other sites More sharing options...
joewilson Posted November 14, 2013 Author Share Posted November 14, 2013 $query is where the array for the data is. It holds all the items which I am then showing in tables as Title / thumb / excerpt. I am not using Ajax or javascript. Its pure Php. Data that I am talking about can be from 10s to 100s of items in array. So how do we go about : That said, how much data are we talking about? If you're really using multiple pages (that is, a new page load for each page), wouldn't it be preferable to have your data resource only return enough data to create one page, and then get the data for the next page on the next page load? Any help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/283875-json-decode-and-get-file-content/#findComment-1458208 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.