was just helping a friend with some code. i was gonna just use this as a temporary post, but it might help someone in the future too, so i'll keep it here.
this code will read a tab delimited file and loop through each line. you can change the delimited
/t to whatever ou want. default is a comma.
PHP Code:
<?
// mysql connection script ...
// tab delimited file
$file = "test_questions.csv";
// open file
$handle = fopen($file, "r");
// loop through results with fgetcsv() function
while(($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
// populate field vars just to make it easier to work with ..
// you could access the $data[] array directly in the sql if you want
$field1 = $data[0];
$field2 = $data[1];
$field3 = $data[2];
$field4 = $data[2];
// etc ...
// build your sql statement
$sql = "insert into table set
testid='1',
category='foo',
field1='".$field1."',
field2='".$field2."',
field3='".$field3."',
field4='".$field4."'";
$result = mysql_query($sql);
}
// close file
fclose($handle);
?>