2012-06-06 33 views
0

我使用下面的代碼迴路通過幾個從我的數據庫鏈接,來檢查的每一個爲什麼我在php中出現這個錯誤?

$con = mysql_connect("localhost","root",""); 
if (!$con) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("tracker", $con); 

$result=mysql_query 
     (" 

     SELECT id,ziel_url FROM wm_mapping WHERE ziel_url LIKE '%websale7%'"); 

if (!$result) 
{ 
    echo 'Could not run query: ' . mysql_error(); 
    exit; 
} 

$rows=array(); 
while ($row=mysql_fetch_assoc($result)) 
{ 
    $rows[] = $row; 
} 
$fp = fopen('url.csv', 'a+'); 
$csv=array(); 
foreach ($rows as $row){ 

     file_get_contents($row['ziel_url']); 
     $response =$http_response_header[29]; 
     $csv[] = trim($row['id']).','.trim($row['ziel_url']).','.trim($response); 


} 
file_put_contents('url.csv', implode("\r\n", $csv), FILE_APPEND); 

頭狀態和行$response =$http_response_header[29];我我得到一個錯誤未定義抵消:

這是什麼意思?

+0

誤差($ http_response_header爲$報頭) { 回聲$頭。 「
\ n」; } – swapnesh

+0

這意味着你的'$ http_response_header'變量中沒有第29個元素,這個變量在任何地方也沒有定義。 – lanzz

+0

yepp您的權利 – lgt

回答

0
$response =isset($http_response_header[29])?$http_response_header[29]:SOMETHING_ELSE; 
+0

因爲它是自動創建的(imho它是來自php開發者的一個可怕的解決方案/實現),並在使用http流如file_get_contents('http://site.com/'))之後插入當前範圍。 – smassey

0

可能是因爲$http_response_header數組中沒有30個元素。嘗試使用var_dump($http_response_header);查看數組內容以查看要使用的元素。 []內嘗試----的foreach

相關問題