Re: preventing duplicate rows?

From: Date: Thu, 13 Apr 2006 07:02:21 +0000
Subject: Re: preventing duplicate rows?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-233863@lists.php.net to get a copy of this message
William Stokes a écrit :
Hello, I'm updating a table with following SQL statement $sql = "INSERT INTO x_ikaluokat (ryhma, ikaluokka) VALUES ('$ryhma','$ikaluokka')"; What would be the best way to test that similar rows doesn't get created to the table? I can't make both columns unique. Can't you define a key in your sql table, to avoid "similar raws" ?
otherwise, you can set an array with both values $my_array[$ryhma] = $ikaluokka; and test for each insert if ( !array_key_exists($ryhma,$my_array)) { $sql = "INSERT ..."; } elseif ( $my_array[$ryhma] != $ikaluokka ) { $sql = "INSERT ..."; } but if you have a lot of insert, the script needs a lot of memory to run properly. N F
Thanks -Will


« previous php.general (#233863) next »