List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 27 2001 10:59pm
Subject:Re: select query for duplicate records
View as plain text  
At 5:46 PM -0500 6/27/01, Pete Kuczynski wrote:
>Thanks Paul!
>ps works great!
>I modified the database with a UNIQUE column like you recommended
>earlier, this will now help in the PHP script to trap the duplicate
>entry and advise the user of the dup.

But if hostname now has a UNIQUE index on it, it won't even be possible
for your table to have duplicate hostname values, other than NULL.

Probably all you need to do is just go ahead and try to insert the record,
and if mysql_affected_rows() is 0, it was a duplicate and was rejected.

>
><?
>     // check for duplicate row
>     $query = "SELECT hostname, COUNT(*) AS count FROM asset
>               GROUP BY hostname HAVING count > 1
>     $result = mysql_query($query);
>             // check if row is returned, if yes error, if no insert
>             if (mysql_num_rows($result) != 0) {
>                     echo "error";
>             } else {
>                     // DO INSERT
>             }
>     ?>
>
>Pete


-- 
Paul DuBois, paul@stripped
Thread
select query for duplicate recordsPete Kuczynski27 Jun
  • Re: select query for duplicate recordsPaul DuBois27 Jun
  • Re: select query for duplicate recordsHannes Niedner28 Jun
  • Re: select query for duplicate recordsBob Hall28 Jun
  • Re: select query for duplicate recordsPete Kuczynski28 Jun
    • Re: select query for duplicate recordsPaul DuBois28 Jun
  • Re: select query for duplicate recordsPete Kuczynski28 Jun