I need those decimals!! Please help..
Moderator: General Moderators
Woehaa...
A new page started when you said that it looked great, didn't check my post...
Oke, here is the code as it is now, please have a look..
A new page started when you said that it looked great, didn't check my post...
Oke, here is the code as it is now, please have a look..
Code: Select all
<?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);
$column= preg_replace('#^((?:(?:(?:[0-9]{1,3}\.(?:[0-9]{3}\.)*)(?:[0-9]{3}))|0|[0-9]*))(,[0-9]+)?$#e','str_replace(\'.\',\'\',\'\\1\').str_replace(\',\',\'.\',\'\\2\')',trim($column, '"'));
$sql2 .= "'{$column}', ";
}
$sql2 = rtrim($sql2, ', ');
$sql2 .= ')';
echo 'Executing: ' . $sql2 . '</br>';
}
mysql_query($sql2) or print(mysql_error() . '<br>');
}
fclose($fp);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
placeafter
Code: Select all
mysql_free_result($result);Code: Select all
$row = mysql_fetch_row ($result);