Friday, 23 August 2013

PHP MySQL search using WHERE IN

PHP MySQL search using WHERE IN

I have my following PHP code which finds the servers which have and tags
assigned to them. In my example its bending, economy. The script gets a
server that has both but displays it twice. What is the best way to stop
this?
Please note that the tags are stored in a seperate table and are obtained
by searching via the server id.
$sql = "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)) AS score,
GREATEST(1, DATEDIFF(NOW(), ss.added)) AS days
FROM servers AS s
LEFT JOIN server_score AS ss
ON s.id = ss.id
ORDER BY score DESC
LIMIT $start, $limit";

No comments:

Post a Comment