how would you create this query using Zend Framework's Zend_Db_Select
SELECT movie.*, count(DISTINCT similar.tag) as shared_tags FROM movie INNER JOIN
( tagged AS this_movie INNER JOIN tagged AS similar USING (tag) )
ON similar.movie = movie.id
WHERE this_movie.movie=<current_movie_id>
AND movie.id != this_movie.movi开发者_StackOverflowe
GROUP BY movie.id
ORDER BY shared_tags DESC
$query = ("SELECT movie.*, count(DISTINCT similar.tag) as shared_tags
FROM movie
INNER JOIN (tagged AS this_movie
INNER JOIN tagged AS similar USING (tag) )
ON similar.movie = movie.id
WHERE this_movie.movie=<current_movie_id>
AND movie.id != this_movie.movie
GROUP BY movie.id ORDER BY shared_tags DESC ");
mysql_query('$query') or die(mysql_error());
Should you use any params in your query don't forget to escape all params with
$param = mysql_real_escape_string($param);
Before feeding them to the sql_query or you'll get bitten by SQL-injection attacks.
精彩评论