someoneneedshelps
Technical User
Hi
Hit a brick wall with this function, it does what I want but one line, I need it to read my lines of data, can anyone help please?
Hit a brick wall with this function, it does what I want but one line, I need it to read my lines of data, can anyone help please?
Code:
function mysql_insert_array($table, $column_list, $filename, $types)
{
$i=0;
$f = fopen($filename, "r");
while (($line = fgetcsv($f)) !== false)
{
$row = $line[0]; // We need to get the actual row (it is the first element in a 1-element array)
$cells = explode(";",$row);
$type = explode(";",$types);
foreach ($cells as $cell)
{
//case staement to find values types ie; int text etc
$myresult = switch_to_get_values($type[$i],$cell);
if($myresult)
$fields[] = "'" . htmlspecialchars($cell) . "'";
else
$fields[] = $cell;
$i++;
}
$value_list = join(',', str_replace("' ","'",$fields));
$query = "INSERT INTO " . $table . " (" . $column_list . ") VALUES (" . $value_list . ")";
}
fclose($f);
return $query;
}