Sorry I gave you a bad example as stated above (thanks, Gerben Jongerius for pointing that out).... the mysql_query needs to be outside the loop. To be accurate this is how that should be set up...
$query = "INSERT INTO ".$table."(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES";
$c = count($headerTable)-1; //<-- not sure about this....
echo "headerTable Count = ".$c;
$numberOfLoops=0;
for($i = 0; $i < $c; $i += 6)
{
// Add the next batch of values to the query string
if($i==0)
{
$query.= "('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
}
else
{
$query.= ", ('".$headerTable[$i]."','".$headerTable[$i+1]."','".$headerTable[$i+2]."','".$headerTable[$i+3]."','".$headerTable[$i+4]."','".$headerTable[$i+5]."')";
}
}
echo $query;
echo 'The number of loops';
echo $numberOfLoops++;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
return true;
}
if you do not move it outside the loop then when you have more than one set of six records to process you will generate a bad query on the second pass. if example what you currently have one the first pass will produce a query that looks like this on the first pass; INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 ') and on the second pass; INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 '), ('','','','','','') this has 2 errors, one is the duplucate data being entered into the table and the other is the empty data on the second pass. If you move the mysql_query to outside of the loop you would get one insert like this; INSERT INTO HeaderRecord(FileIdentifier, Version, ReceiverIdentifier, Date, Time, FileGenerationNumber) VALUES('SOF','1','1500','19970519','112904','1 '), ('','','','','','') That will take care of the duplcate data issue. To fix the blank data look at your data source. Something is wrong with it adding an extra line as your output shows; headerTable Count = 7 so one extra row is being added to your data source before it hits this function, this should be looked at. Hope this helps Chris J