我使用了这个查询:
function get_latest_news()
{
$sql = "SELECT TOP 5 * FROM ArkibBerita
WHERE code='BERITA' AND Enable = 'Y' AND Lang = 'EN'
ORDER BY position ASC";
$query = $this->db->query($sql);
return $query->result();
}
每条记录仅显示3天。我可以知道如何查询仅显示3天的数据。
谢谢你,niena
答案 0 :(得分:0)
试试这个
$sql = "SELECT TOP 5 * FROM ArkibBerita
WHERE code='BERITA' AND Enable = 'Y' AND Lang = 'EN'
AND BeritaDate >= NOW() - INTERVAL 3 DAY // <--- this line
ORDER BY position ASC";
$query = $this->db->query($sql);
return $query->result();
答案 1 :(得分:0)
试试这个
SELECT TOP 5 * FROM ArkibBerita
WHERE code='BERITA' AND Enable = 'Y' AND Lang = 'EN'
AND BeritaDate >= curdate( )
AND BeritaDate <= curdate( ) + INTERVAL 3 DAY
ORDER BY position ASC
OR
SELECT TOP 5 * FROM ArkibBerita
WHERE code='BERITA' AND Enable = 'Y' AND Lang = 'EN'
AND BeritaDate BETWEEN curdate( )
AND curdate( ) + INTERVAL 3 DAY
ORDER BY position ASC