I have looked over the query again and the results you are getting make sense since no matter what the values are the last condition looking for the id being greater than 0 will always be true.
You should be able to update this so that the last condition will only be true if the first two are not and get the result you are looking for. I think the where clause will need to look like this:
WHERE (idcategory_product=colname) OR (idcollection_product=colname2) OR (idcategory_product <> colname AND idcollection_product <> colname2 AND product.id > 0)
Let me know if you have any problems with this and we can do some php to hold the where clause in a variable. In my testing this returned the results I was looking for.