tomtimms Posted April 29, 2010 Share Posted April 29, 2010 I have 4 columns in my table. ID, Name,Site,Status Id is auto_incremented, I am trying to Insert new rows that will skip pass any duplicates. Let's assume the database has 1 record already. ID Name Site Status 1 | Bob | 1 | 4 I want to add (Bob|1|4) and then (Bob|2|4). The first entry won't be inserted as its duplicated however the second will as Site is different. I tried using INSERT IGNORE however whenever SITE was different it wouldn't INSERT the new record. A name is associated to a site and is given a status, so I have different name's that can be assigned to different sites. I hope this makes some sense. Any help or starting point would be great. Link to comment https://forums.phpfreaks.com/topic/200218-mysql-ingnore-duplicate/ Share on other sites More sharing options...
otuatail Posted April 29, 2010 Share Posted April 29, 2010 Firstly this is an SQL problem so should be on the other forum. You would need to do something like SELECT ID from MyTable WHERE Name = 'Bob and ' Site = 1 and Status = 4; $query = mysql_query($sql); $total = mysql_num_rows($query); if($total == 0) { // ok to go ahead and insert } Link to comment https://forums.phpfreaks.com/topic/200218-mysql-ingnore-duplicate/#findComment-1050721 Share on other sites More sharing options...
otuatail Posted April 29, 2010 Share Posted April 29, 2010 Sorry that should have read SELECTcount( ID) as Totla from MyTable WHERE Name = 'Bob' and Site = 1 and Status = 4; $query = mysql_query($sql); $total = mysql_num_rows($query); if($total == 0) { // ok to go ahead and insert } This is better if $count == 0 no problem if $count == 1 problem this already exsists if $count >1 big problem this should not have happend report this to the webmaster !!! Link to comment https://forums.phpfreaks.com/topic/200218-mysql-ingnore-duplicate/#findComment-1050724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.