2016-12-03 30 views
0

我不熟悉這種錯誤Undefined error offset: 1。我該如何解決這個錯誤?如何解決未定義的偏移量:1

這裏是我的代碼連同我的查詢:

SELECT document_crew_id,doc_number,full_name,id,doc_type,date_issue,date_expiry,place_of_issue,crew_status, 
GROUP_CONCAT(doc_number) as document_number, 
GROUP_CONCAT(date_issue) as date_issued, 
GROUP_CONCAT(date_expiry) as date_expired, 
GROUP_CONCAT(place_of_issue) as place_issueda 
from crew_documents_table join info 
on crew_documents_table.document_crew_id = info.id where doc_type = '1' or doc_type = '2' and crew_status = 'LINEUP PENDING' group by full_name 

     $value = $row1['document_number']; 
     $value = explode(",", $value); 
     $doc_numn2 = $value[1]; 

預先感謝您

+0

好吧,顯然你的$值沒有逗號,所以$ doc_numn2只有一個字段,索引爲0.如何防止它?在你訪問它之前檢查你的數據是否存在,例如用'isset()' –

+0

我應該在哪裏放置逗號? –

+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – HPierce

回答

1

我認爲以下行導致錯誤:

$doc_numn2 = $value[1]; 

您需要檢查有在嘗試訪問該索引之前,該索引是數組項目:

$doc_numn2 = isset($value[1]) ? $value[1] : null; 

您正在處理的某一行可能沒有以逗號分隔的文檔編號值。

希望這會有所幫助。