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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.