任何人都可以幫我解決這個錯誤嗎?一直在看它,但一直沒有能夠得到它的工作。前一段時間寫了這篇文章,覺得它在我最後一次離開它時起作用了,但是當我重新訪問它時,我還沒有能夠運行它。感謝所有的幫助。注意:試圖獲取非對象的屬性在.../search.php在線46
說明:試圖獲得非對象的屬性在/Applications/MAMP/htdocs/search/views/layouts/search.php上線46
警告:提供的foreach無效參數()/應用程序/MAMP/htdocs/search/views/layouts/search.php on line 46
第46行是來自最後一行代碼的第4行。
<?php
include($_SERVER['DOCUMENT_ROOT'].'/'.'search/scripts/JSON.php');
include($_SERVER['DOCUMENT_ROOT'].'/'.'search/scripts/search_fns.php');
$searchquery = urlencode(isset($_GET['search']) ? $_GET['search'] : "news");
// Google Search API
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q="
. $searchquery
."&key=ABQIAAAAYIeqEnf9yNjBzcHJK7yDdhSklBzi76D_F0lniPI7JR27aK7eCBSU-xpNs1axVS45y_PX_7_ibsScUA&userip=USERS-IP-ADDRESS&rsz=filtered_cse";
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://localhost");
$body = curl_exec($ch);
curl_close($ch);
// process the JSON string
$json = new Services_JSON;
$json = $json->decode($body);
$formattedresults = "";
$rating = "";
$search = $searchquery;
?>
<style type="text/css">
td img {display: block;}
</style>
<div id="main">
<?php
foreach($json->responseData->results as $searchresult)
{
if($searchresult->GsearchResultClass == 'GwebSearch')
{
基本調試:var_dump($ json); – 2012-07-08 22:31:32