Jump to content

how to check if duplicate rows across multiple columns


mpsn

Recommended Posts

Hi, I need help to check multiple rows for many columns, so that the script won't re-insert a duplicate entry. For eg:

 

$isRowExist=mysql_query("SELECT (field1,field2) from table1 WHERE field1='$f1' AND field2='$f2' ");

 

if(mysql_num_rows($isRowExist)==1)

  print "already in table1!";

else

  //proceed to insert into table table1

 

*BUT I tried this and it says mysql_num_rows expects resource, and this warning only shows when I have multipel columns I want to compare (it works just fine with one column in the WHERE clause above)

 

Please help!

Do not double post. As stated in your previous post, the query is failing for some reason. You need to see what the error is by checking mysql_error()

 

Although there could be syntax errors with respect to field/table names your problem is likely due to the fact that you put the SELECT field within parens. However, you should simply make the fields unique and to the INSERT query instead of doing a SELECT query first.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.