我在订购此查询时遇到问题,我尝试过:
$query .= " ORDER BY t.id DESC";
并没有显示任何内容。有光吗?
$query = "SELECT t.name, t.id FROM #__k2_tags as t";
$query .= " LEFT JOIN #__k2_tags_xref tags_xref ON tags_xref.tagID = t.id";
$query .= " LEFT JOIN #__k2_items i ON tags_xref.itemID = i.id";
$query .= " LEFT JOIN #__k2_categories c ON c.id = i.catid";
$query .= " WHERE t.published=1";
$query .= " AND i.published=1 ";
$query .= " AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." ) ";
$query .= " AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )";
$query .= " AND i.trash=0 ";
$query .= " AND i.access <= {$aid}";
$query .= " AND c.published=1 ";
$query .= " AND c.trash=0 ";
$query .= " AND c.access <= {$aid}";
答案 0 :(得分:1)
哈希符号表示php和MySQL中的注释。如果#__ k2_tags真的是你的表名,为了你的缘故,我希望它不是那么你需要在它周围添加反引号
$query = "SELECT t.name, t.id FROM `#__k2_tags` as t";
参考: http://dev.mysql.com/doc/refman/5.1/en/comments.html
使您的查询最终看起来像MySQL,这是一个无效的错误语法查询。
$query = "
SELECT t.name, t.id FROM
LEFT JOIN
LEFT JOIN
LEFT JOIN
WHERE t.published=1
AND i.published=1
AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )
AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )
AND i.trash=0
AND i.access <= {$aid}
AND c.published=1
AND c.trash=0
AND c.access <= {$aid}"