我在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客户端上这很顺利)。
答案 0 :(得分: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
答案 1 :(得分: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