I need to pull out the info of the Production Company and Distribution Company for any given movie and I'm using the Freebase for this. Happens I never used JSON and don't know how to integrate the query with my PHP file.
The tutorials I've been reading are not at all clear on this so as always I come here to get the help I always get! :)
So... The info I need to pull out is this Freebase Query Editor
And the PHP I have is this (commented lines are the lines I'm sure that are wrong and/or lines from the tutorial I followed with no sucess here:
$moviename = "The Matrix";
// [{ "name": "The Matrix", "type": "/film/film", "production_companies": [{ "name": null }], "distributors": [{ "distributor": [{ "name": null }] }] }]
$simplequery = array('name'=>$moviename, 'type'=>"/film/film", 'production_companies'=>array('name'=>null));
//{"id":"/topic/en/philip_k_dick", "/film/writer/film":[]}
//$simplequery = array('id'=>$_POST["freebasewriter"], 'name'=>null, '/film/writer/film'=>array(array('name'=>null, 'id'=>null)));
$queryarray = array('q1'=>array('query'=>$simplequery));
$jsonquerystr = json_encode($queryarray);
#run the query
$apiendpoint = "http://sandbox.freebase.com/api/service/mqlread?queries";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$apiendpoint=$jsonquerystr");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonresultstr = curl_exec($ch);
curl_close($ch);
$jsonquerystr = urlencode(json_encode($queryarray) );
//print_r($resultarray);
//$produtoraarray = $resultarray["q1"]["result"]["production_companies"];
//print_r($produtoraarray);
//$produtorarray = $resultarray["q1"]["result"][];
//$freebaseserver = "http://sandbox.freebase.com";
Can anyone give me a help here? Thanks in advance!
Appreciate it a lot and Merry Christmas by the way :)
EDIT @Yanir Shahak answer helped and now I'm getting this:
Array ( [code] => /api/status/ok [q1] => Array ( [code] => /api/status/error [messages] => Array ( [0] => Array ( [code] => /api/status/error/mql/result [info] => Array ( [count] => 3 [result] => Array ( [0] => Array ( [name] => Warner Bros. Entertainment ) [1] => Array ( [name] => Village Roadshow Pictures ) [2] => Array ( [name] => Silver Pictures ) ) ) [message] => Unique query may have at most one result. Got 3 [path] => production_companies [query] => Array ( [name] => The Matrix [production_companies] => Array ( [error_inside] => . [name] => ) [type] => /film/film ) ) ) ) [status] => 200 OK [transaction_id] => cache;cache02.sandbox.sjc1:8101;2011-12-24T02:01:34Z;0004 )
Now ... How do I take the data out of there into arrays I can use?
This code is not working as I get undefined indexes
//print_r($resultarray);
//$produtoraarray = $resultarray["q1"]["result"]["production_companies"];
//print_r($produtoraarray);
//$produtorarray = $resultarray["q1"]["result"][];
//$freebaseserver = "http://sandbox.freebase.com";