-4

I need a little help in putting a code in the below sql code.

My code is -

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

I want to put it inside the below query:

$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());

Please help!

I need the result as below:

$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());

Please correct the above result code!

4

1 回答 1

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

于 2013-02-05T19:47:36.913 回答