今天列出记录顺序..?
我该怎么做?
我的SQL查询:
$sql = $db->sql(
"SELECT haber.h_id, haber.k_id, haber.baslik, haber.baslik_renk, haber.resim, haber.k_icerik, haber.link, haber.time, kategori.baslik as kategori
FROM haber LEFT JOIN kategori ON haber.k_id=kategori.k_id
WHERE kategori.onay='1' AND haber.onay='1' AND haber.time<='".time()."' ORDER BY haber.time DESC LIMIT 30");
答案 0 :(得分:0)
尝试将unix时间戳转换为日期DATE(FROM_UNIXTIME(haber.time))
并将其与DATE(SYSDATE())
进行比较(sysdate将返回当前数据库日期):
$sql = $db->sql(
"SELECT haber.h_id,
haber.k_id,
haber.baslik,
haber.baslik_renk,
haber.resim,
haber.k_icerik,
haber.link,
haber.time,
kategori.baslik as kategori
FROM haber
LEFT JOIN kategori ON haber.k_id=kategori.k_id
WHERE kategori.onay='1'
AND haber.onay='1'
AND DATE(FROM_UNIXTIME(haber.time)) = DATE(SYSDATE())
ORDER BY haber.time DESC
LIMIT 30"
);
您也可以使用服务器日期,如下所示:
AND DATE(FROM_UNIXTIME(haber.time)) = DATE(" . date('Y-m-d') . ")