mpsn Posted November 2, 2011 Share Posted November 2, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/250324-how-to-check-if-duplicate-rows-across-multiple-columns/ Share on other sites More sharing options...
Psycho Posted November 2, 2011 Share Posted November 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250324-how-to-check-if-duplicate-rows-across-multiple-columns/#findComment-1284401 Share on other sites More sharing options...
freelance84 Posted November 2, 2011 Share Posted November 2, 2011 mysql_error Check your query before doing anything else: if(!$isRowExist) { echo mysql_error(); } (too slow to respond ha!) Quote Link to comment https://forums.phpfreaks.com/topic/250324-how-to-check-if-duplicate-rows-across-multiple-columns/#findComment-1284402 Share on other sites More sharing options...
mpsn Posted November 2, 2011 Author Share Posted November 2, 2011 Yes, it was the parenthesis around the (title) in the SELECT query, thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/250324-how-to-check-if-duplicate-rows-across-multiple-columns/#findComment-1284413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.