PHP MySQL search using WHERE IN -


i have following php code finds servers have , tags assigned them. in example bending, economy. script gets server has both displays twice. best way stop this?

please note tags stored in seperate table , obtained searching via server id.

php code:

$query = "select s.id, s.name, s.ip, s.port, ss.id, ss.votes, ss.added, (1.6 * ss.votes + .053) * greatest(1, datediff(now(), ss.added)) score, greatest(1, datediff(now(), ss.added)) days, st.server_id, st.server_tags $tbl_name s left join server_score ss on s.id = ss.id left join server_tags st on s.id = st.server_id st.server_tags in ($sstag)"; 

results enter image description here

full script http://pastebin.com/5whapesd

join subquery combines rows same server id:

select ... ... left join (select server_id, group_concat(server_tags) server_tags            server_tags            server_tags in ($sstag)            group server_id) st on s.id = st.server_id 

alternatively, can use original query, put group_concat(server_tags) in mainselectclause andgroup s.id` @ end.

if want servers match all tags, not of them, can change to:

left join (select server_id, group_concat(server_tags) server_tags, count(*) tag_count            server_tags            server_tags in ($sstag)            group server_id            having tag_count = $sstag_count) st 

you need set $sstag_count number of tags in $sstag.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -