0

i am not familiar with this kind of error Undefined error offset: 1. how im i going to fix this error?

here is my code together with my query:

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];

thank you in advance

adrian pascua
  • 31
  • 1
  • 3
  • 9
  • well, apparently your $value doesn't have a comma in it, so $doc_numn2 has only one field, with the index 0. how to prevent it? check if your data exists before you access it, for example with `isset()` – Franz Gleichmann Dec 03 '16 at 19:05
  • where should i put the comma? – adrian pascua Dec 03 '16 at 19:07
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – HPierce Dec 03 '16 at 19:37

1 Answers1

2

I assume the following line is causing the error:

$doc_numn2 = $value[1];

You need to check there is an array item at that index before trying to access it:

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

It's likely that a certain row you are processing doesn't have a document number value that is comma separated.

Hope this helps.

Ben Plummer
  • 449
  • 3
  • 9