1
<?php
        $database = & JFactory::getDBO();
        $query = "SELECT asset_id FROM #__content WHERE state = 1";
        $database->setQuery( $query );
        $count_at = $database->loadObjectList();
        $count_nbr = count($count_at);
?>

所以$count_nbr返回所有创建和发布的文章,但我需要添加“今天”过滤器。如果某些大师可以请... 需要 2 种类型的过滤器:“1 天”和“一周”...

更新:添加$date = date (Y-m-d);amd 修改字符串SELECT asset_id FROM #__content WHERE state = 1 AND publish_up = $date;无助于导致 mysql Ymd H:i:s 中的 publish_up,我需要忽略时间戳...

4

1 回答 1

1

要获得今天发表的文章:

$today = date('Y-m-d');
$query = "SELECT asset_id FROM #__content WHERE state = 1 AND DATE_FORMAT(publish_up, '%Y-%m-%d') = '$today'";
...

这使用 MySQLDATE_FORMAT()函数将发布的日期格式化为Y-m-d格式化,以便您可以比较它。

要获得本周发表的文章,请使用以下YEARWEEK()功能:

$query = "SELECT asset_id FROM #__content WHERE state = 1 AND YEARWEEK(publish_up) = YEARWEEK(NOW())";
于 2012-12-18T13:49:00.990 回答