2

I have a WordPress site for people with Multiple Sclerosis and to assist them in finding current clinical trials that are recruiting participants I have an external JSON file of search results I want to display on my site.

Here is a sample output from the JSON:

{"intervention_browse":{"mesh_term":["Copolymer 1"]},"id_info":{"nct_id":"NCT00004814"},"sponsors":{"collaborator":[{"agency":"University of Maryland","agency_class":"Other"}],"lead_sponsor":{"agency":"National Center for Research Resources (NCRR)","agency_class":"NIH"}},"overall_status":"Completed","condition_browse":{"mesh_term":["Multiple Sclerosis","Sclerosis","Multiple Sclerosis, Relapsing-Remitting"]}}

What would be the best way to do this? An example using cURL or JSON_decode would be nice. (I only know enough to get myself into trouble, so assume I'm in kindergarten please. :) )

Since it's going into a WordPress site, should I use PHP or javascript or a combination of both for displaying it?

Once I get the information to display on my site I have no problem styling it with css. Getting it on the page is my main issue.

I have installed a plugin that allows me to add php directly into any page or post using shortcodes, but what code to put there is what's holding me up.

Here is the JSON file:http://api.lillycoi.com/v1/trials/search.json?query=cond:%22Multiple+Sclerosis%2C+Relapsing-Remitting%22&fields=id_info.nct_id,condition_browse,sponsors,intervention_browse,overall_status&limit=1000

5
  • Does php.net/manual/en/function.json-decode.php not help? Please include the attempted code in your question. Commented Sep 18, 2013 at 20:28
  • I don't understand how to decode JSON and implement it, so I have no failed code to show you, rather I'm asking for basic help to get it working. Commented Sep 18, 2013 at 20:31
  • In that case, start by reading the PHP manual. Check the link I gave above. Also, the search feature on StackOverflow is awesome. Here's one post to get you started: stackoverflow.com/questions/6571090/ Commented Sep 18, 2013 at 20:34
  • i would use a client-side template that can consume json. angular works, but that's probably overkill. the datatables jQuery plugin can consume JSON if you want to offer a datagrid. Commented Sep 18, 2013 at 20:35
  • Thanks to you both and I apologize for asking something that has been answered before. Although I have been searching Stackoverflow and elsewhere for hours, I didn't understand the answers enough to take what I found and customize it for my own use. Commented Sep 18, 2013 at 20:43

1 Answer 1

2

You can follow it:

<?php
    $url = "http://api.lillycoi.com/v1/trials/search.json?query=cond:%22Multiple+Sclerosis%2C+Relapsing-Remitting%22&fields=id_info.nct_id,condition_browse,sponsors,intervention_browse,overall_status&limit=1000";

    $json = file_get_contents($url);
    $data = json_decode($json, TRUE);
?>

You can use var_dump or print_r to know what's in your data :

<?php var_dump($data); ?>

or

  <?php print_r($data); ?>

The TRUE returns an array instead of an object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that! Do I wrap that in php tags or is that javascript? (I told you I'm clueless). :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.