Jump to content

json decode and get file content


joewilson

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$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.

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.