我正在使用imdb api进行ajax调用以搜索电影,我注意到有空格的查询我得到错误; Undefined variable: id in C:\wamp\www\..
获取部分结果。我该如何解决这个问题?
($row = mysql_fetch_assoc($sql));
$id = $row['imdb_id'];
$test = "http://imdbapi.org/?id=tt00".$id."&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple&business=0&tech=0";
$cont = file_get_contents ($test);
$data = json_decode($cont, true);
$title = $data['title'];
echo "$title";
答案 0 :(得分:1)
此代码对我来说非常有用(在我的本地服务器上测试)
<?php
$row = array('imdb_id'=> 4);
//print_r($row);
$id = $row['imdb_id'];
$test = "http://imdbapi.org/?id=tt00".$id."&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple&business=0&tech=0";
$cont = file_get_contents ($test);
$data = json_decode($cont, true);
$title = $data['title'];
echo "$title";
输出 - Un bon bock
从此行中删除(
和)
[感谢Marcel] -
($row = mysql_fetch_assoc($sql));
至$row = mysql_fetch_assoc($sql);