开发者

JOIN in JOIN with Zend

开发者 https://www.devze.com 2023-01-25 23:25 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消