如何显示MySQL不超过一天的行?

时间:2012-04-26 17:19:32

标签: mysql joomla

我想显示新闻,例如从昨天开始。这是我的查询的样子。是否有任何神奇的代码可以做到这一点?

$query = '
    SELECT a.*, 
           CASE WHEN CHAR_LENGTH(a.alias) THEN  CONCAT_WS(":", a.id, a.alias)
                                          ELSE a.id END as slug,
           CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(":", b.id, b.alias) 
                                          ELSE b.id END as catslug,
           b.title as category_title, 
           b.alias as categoryalias, 
           b.params as categoryparams,
           u.name AS author
    FROM #__content as a 
    LEFT JOIN #__categories as b ON a.catid = b.id
    LEFT JOIN #__users AS u ON u.id = a.created_by
    WHERE ' . $where. ' 
    ORDER BY ' . $orderby. ' 
    LIMIT ' . $limit;

1 个答案:

答案 0 :(得分:1)

"魔法"代码行应该在WHERE子句中。

e.g。如果你的日期只有YYYY-MM-DD

$query .= 'WHERE b.created_date = '.$db->quote( date('Y-m-d', strtotime('-1 day')) ).'

e.g。如果您的日期列是YYYY-MM-DD H:i:s

$query .= 'WHERE DATE_FORMAT(b.created_date,"%Y-%m-%d") = '.$db->quote( date('Y-m-d', strtotime('-1 day')) ).'