0
$tsvhandle = fopen($tsvfile, 'r'); 
while (($data = fgetcsv($tsvhandle, 1000, ";")) !== FALSE) {
    $result = mysql_query("SELECT `post_id` FROM `charvest_postmeta` WHERE `meta_key` = '_sku' AND `meta_value` = '".$data[2]."'") or die($result."<br/><br/>".mysql_error());
    while($row = mysql_fetch_array($result)){
        echo $row['post_id']. "</br>";

    }
}

I receive " PHP Notice: Undefined offset: 2", but I don't understand what's the problem. Please help to me to fix that.

Thank you!

2
  • 1
    $data[2] does not exist, what is in fgetcsv() ? Commented Jan 5, 2013 at 21:18
  • I can print $data[2]. It's a CSV file. Commented Jan 5, 2013 at 21:23

1 Answer 1

1

$data just don't have 3rd column (indexed 2) on some iteration.

You can check that within a loop: if (!isset($data[2])) { ...

Sign up to request clarification or add additional context in comments.

3 Comments

$data[2] exists, I can print it, but it's not working inside the mysql query. $data is a csv file, but I had to rebuild it.
If you have the notice, it means there is at least one row where $data[2] does not exist. Maybe an empty line at the end ?
Yes, there was an empty line. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.