Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the end i need to somehow tell it to skip the rows that have nothing on them:
Code: <?php // define table name and csv file location and name
// delete all old data $sql2 = "DELETE FROM ".$table." WHERE supp_id = ".$supp_id."";
mssql_query($sql2) or die("Failed to insert to db ");
// Define DB mapping (Fill in rest of the mapping in order of appearance in CSV) $fields = array( "manufacturer", "ignore", "manf_part_no", "supp_part_no", "description", "rrp", "cost_price", "avail_qty");
// Open the CSV file $handle = fopen($csvupload, "r") or die("Unable to open $csvupload for reading");
// Get each row's values to an array $i = 1; // define tab delimited or comma while (($data = fgetcsv($handle, 512, ",")) !== FALSE) { // First row's headers and not included, otherwise row field count must match wanted field count if(count($data)==count($fields) && $i!=1){ $rows[] = $data; } elseif(count($data)!=count($fields)) { die("Erroneus CSV file: incorrect field count on row $i"); } $i++; }
// Close file handle fclose($handle);
// Create SQL if(count($rows)==0) die("No rows found in user file");