I cannot use 'ON DUPLICATE VALUE' to update/replace values as this is only available on MySQL 4.1+ and my host runs Mysql 4.0.21.
Therefore can you clarify that I can use REPLACE into as I have tried this without success:
here is my code- how do I adapt it so it uses REPLACE...

$values = array(); 
foreach($scorearray as $key => $score) 
{ 
 // each element will be a parenthesized list of values: 
$values[] = sprintf("('%s','%s',%d,'%s')", $username, $qualitysystem[$key], $score, $searchurl[$key]); 
} 
// merge values into sequence of comma-separated value lists: 
$valueList = implode(',', $values); 
// create the SQL: 
$sql = "INSERT INTO `qualityuserscores` (`username`, `qualitysystem`, `score`, `search_url`) VALUES $valueList"; 

$result = mysql_query($sql) or exit(mysql_error()); 

}

    The manual says:

    REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.

    So alter your insert statement to

    "REPLACE INTO `qualityuserscores` (`username`, `qualitysystem`, `score`, `search_url`) 
    VALUES $valueList"

    remember though that it won't replace unless you have a primary key or unique index.

      Write a Reply...