Hi,
I'm importing score values into a Score table.
Data is inserted, but the decimal values are all zero.
This is the data from the csv file:
Id InschrijvingId SerieNr Tijd Punten
-1342470134 -2066231603 1 10,53 100
1642315376 -2036312949 1 14,63 100
1752376856 -2000188461 1 9,61 100
This is how i't's shown in the table:
Id |InschrijvingId SerieNr Tijd Punten
-932280388 |529280601 1 14.00 100
-1847839509 | -2128794105 1 19.00 100
1783236609 |-2105805680 1 19.00 100
This is the script I use:
Can anyone help me please to correct this ???
Thanks a lot !
I'm importing score values into a Score table.
Data is inserted, but the decimal values are all zero.
This is the data from the csv file:
Id InschrijvingId SerieNr Tijd Punten
-1342470134 -2066231603 1 10,53 100
1642315376 -2036312949 1 14,63 100
1752376856 -2000188461 1 9,61 100
This is how i't's shown in the table:
Id |InschrijvingId SerieNr Tijd Punten
-932280388 |529280601 1 14.00 100
-1847839509 | -2128794105 1 19.00 100
1783236609 |-2105805680 1 19.00 100
This is the script I use:
Code:
<?php
mysql_select_db($database_ASN, $ASN);
if (!file_exists('Score.csv'))
{
die ("Er is geen Score bestand aangetroffen, voer eerst de Upload uit vanaf het Website menu !");
}
$fp = fopen('Score.csv', 'r');
// first line has column names
$data = fgetcsv($fp, 2048, ';');
$columns = array();
foreach($data as $column)
$columns[] = trim($column, '"');
$sql = 'INSERT INTO testscore (';
$sql .= implode($columns, ', ');
$sql .= ') VALUES (';
// next lines have values
while (($data = fgetcsv($fp, 2048, ';')) !== FALSE)
{
$checksql = "SELECT Id FROM testscore WHERE Id='".$data[0]."'";
$result = mysql_query($checksql) or die(mysql_error());
$row = mysql_fetch_row ($result);
if ($row[0])
{
$sql2 = "UPDATE testscore SET ";
$sql_clause=array();
foreach ($data as $key=>$column)
{
if ($key != 0)
{
$sql2 .= $columns[$key]."='".mysql_real_escape_string($column)."',";
}
}
$sql2 = rtrim($sql2, ",");
$sql2 .= " WHERE ".$columns[0]." = '".mysql_real_escape_string($data[0])."'";
} else
{
$sql2 = $sql;
foreach($data as $column)
{
$column = mysql_real_escape_string($column);
$sql2 .= "'{$column}', ";
}
$sql2 = rtrim($sql2, ', ');
$sql2 .= ')';
// echo 'Executing: ' . $sql2 . '</br>';
}
mysql_query($sql2) or print(mysql_error() . '<br>');
}
fclose($fp);
Can anyone help me please to correct this ???
Thanks a lot !