1

我在 ExpressionEngine 1.6.4(非常旧的版本)中收到有关此代码的 MySQL 错误

{exp:query  limit="10" paginate="bottom"
    sql="SELECT 'gallery' AS `content_type`, `cat_id` AS `entry_id`, `recent_entry_date` AS `entry_date`
        FROM `exp_gallery_categories`
        WHERE `gallery_id` = 9 AND total_files > 0
        UNION
        SELECT 'video' AS `content_type`, `entry_id`, `entry_date`
        FROM `exp_weblog_titles`
        WHERE `weblog_id` = 6 ORDER BY `entry_date` DESC"

    }
<p>{content_type} - {entry_id} - {entry_date format="%d %F %Y"}</p>
{paginate}{pagination_links}{/paginate}
{/exp:query}

MySQL 返回:

MySQL ERROR: Error Number: 1054
Description: Unknown column 'entry_date' in 'order clause'
Query: SELECT COUNT(*) AS count FROM `exp_gallery_categories` WHERE `gallery_id` = 9 AND total_files > 0 UNION SELECT COUNT(*) AS count FROM `exp_weblog_titles` WHERE `weblog_id` = 6 ORDER BY `entry_date` DESC

似乎 EE 在 MySQL 之前修改了我的查询并使其失败(在 SQL 客户端上这很顺利)。

4

2 回答 2

1

答案是修补mod.query.php以停止修改查询

$query = $DB->query("SELECT COUNT(*) AS count FROM ({$sql}) AS query");

这是 Dom Stubbs 的终极深入回答:ExpressionEngine 1 Query Module and Ordering SQL UNION

于 2012-12-11T18:06:19.827 回答
0

我假设您的选择查询有效。试试下面:

 sql="SELECT * FROM 
        (SELECT gallery AS content_type, cat_id AS entry_id, 
          recent_entry_date AS entry_date
          FROM exp_gallery_categories
          WHERE gallery_id = 9 AND total_files > 0
          UNION
          SELECT video AS content_type, entry_id, entry_date
          FROM exp_weblog_titles
          WHERE weblog_id= 6 
         ) AS TEMP
       ORDER BY entry_date DESC"

编辑:计数查询:

         SELECT COUNT(*) AS count 
         FROM 
            ( SELECT COUNT(*) AS count,
              recent_entry_date AS entry_date
              FROM exp_gallery_categories 
              WHERE gallery_id = 9 AND total_files > 0 
              UNION 
              SELECT COUNT(*) AS count,
              entry_date
              FROM exp_weblog_titles 
              WHERE weblog_id = 6 
           ) AS TEMP 
         ORDER BY entry_date DESC
于 2012-12-10T04:11:44.353 回答