I'll start again,
Lets say My data is:
Table element (id,name,....)
1, name element 1, ....
2, name element 2, ....
3, name element 3, ....
Table tags (id,name,id_element, ....)
1, happy , 1
2, result, 1
3, very , 1
4, element, 2
5, another, 3
6, element, 1
7, happy, 2
So if search is 'very, happy,element,result': Results i would like
1) element with id = 2 because it has all tags
2) element with id = 1 because it has the tag 'element' and the tag 'happy' (only 2 less taggs)
3) .... (only 3 less taggs)
So if search is 'happy,element': Results i would like
1) element with id = 1 because it has all tags (and no more)
2) element with id = 2 because it has the tag 'element' and the tag 'happy' (and two more tags)
3) .... and 3 more tags
This is an echo to my query:
(it doesn't fit al requirements i wrote, but its first test to find with matched tags)
SELECT element.id as id_deseada,tagg.* FROM element,tagg WHERE tagg.id_element = element.id AND tagg.nombre IN ('happy','tagg','result') GROUP BY tagg.id_element ORDER BY element.votos
This returns 10 duplicated elements... :S and doen't even have all taggs (and on database there are taggs with 'happy' results)
if it helps, thats how i get the elements of a tag (by name and with only one tagg)
$query = "SELECT element.id FROM element,tagg WHERE tagg.nombre = '$nombre_tagg' AND tagg.id_element = element.id AND lan = '$lan' GROUP BY tagg.id_element";
I hope it's a bit easier to understand now, excuse my english.. :)
Thanks a lot for you possible aportation!