2013-02-05 62 views
-4

我需要一點幫助,把代碼放在下面的sql代碼中。任何人都可以幫我把下面的代碼放在sql中嗎?

我的代碼 -

torrentlang.name AS lang_name, FROM torrentlang LEFT JOIN torrentlang ON torrentlang = torrentlang.id 

我希望把它下面的查詢中:

$query = " SELECT 
        torrents.id, 
        torrents.category, 
        torrents.name, 
        torrents.image1, 
        torrents.added, 
        torrents.size, 
        torrents.hits, 
        torrents.banned, 
        torrents.comments, 
        torrents.seeders, 
        torrents.leechers, 
        torrents.times_completed, 
        categories.name   AS cat_name, 
        categories.parent_cat AS cat_parent 
       FROM torrents 
        LEFT JOIN categories 
        ON category = categories.id 
       WHERE categories.parent_cat = 'Movies' 
       ORDER BY added DESC 
       LIMIT 2"; 
$query12 = mysql_query($query)or die(mysql_error()); 

請幫幫忙!

我需要的結果如下:

$query = "SELECT 
       torrents.id, 
       torrents.category, 
       torrents.name, 
       torrents.image1, 
       torrents.added, 
       torrents.size, 
       torrents.hits, 
       torrents.banned, 
       torrents.comments, 
       torrents.seeders, 
       torrents.leechers, 
       torrents.times_completed, 
       categories.name   AS cat_name, 
       categories.parent_cat AS cat_parent 
      FROM torrents 
       LEFT JOIN categories 
       ON category = categories.id, 
       torrentlang.name AS lang_name, 
       FROM torrentlang 
       LEFT JOIN torrentlang 
       ON torrentlang = torrentlang.id 
      WHERE categories.parent_cat = 'Movies' 
       AND torrentlang.id = '3' 
      ORDER BY added DESC 
      LIMIT 2"; 
$query12 = mysql_query($query)or die(mysql_error()); 

請更正上述結果的代碼!

+2

究竟你需要哪些幫助? –

+1

如果您的問題正在加入查詢,則還需要表定義。 – scones

+0

需要在$ query12中放置上面一行「torrentlang」而不更改任何現有代碼 – Jaki

回答

1

試試這個

SELECT torrents.id, torrents.category, torrents.name, torrents.image1, torrents.added, torrents.size, torrents.hits, torrents.banned, torrents.comments, torrents.seeders, torrents.leechers, torrents.times_completed, categories.name AS cat_name, categories.parent_cat AS cat_parent ,torrentlang.name AS lang_name 
FROM torrents 
LEFT JOIN categories ON torrents.id = categories.id 
LEFT JOIN torrentlang ON torrents.id = torrentlang.id 
WHERE categories.parent_cat = 'Movies' 
AND torrentlang.id = 3 
ORDER BY added DESC LIMIT 2 

假設torrents.id = categories.idtorrents.id = torrentlang.id

+0

非常感謝:)你歡迎:) – Jaki

+0

! –

相關問題