Re: preventing duplicate rows?

From: Date: Thu, 13 Apr 2006 07:00:52 +0000
Subject: Re: preventing duplicate rows?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-233862@lists.php.net to get a copy of this message
William Stokes wrote:
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.
You could query before hand: $qry = "select count(*) from table where field1='x' and field2='y'"; $result = mysql_query($qry); $count = mysql_fetch_assoc($result, 0); if ($count == 0) { // do insert... } -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#233862) next »