php - mysql order by today

235

Listing records order by today ..?

how can i do that?

my sql query:

$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");
  • "time" is column
  • Unix Timestamp formatted
275

Answer

Solution:

Try converting the unix timestamp to dateDATE(FROM_UNIXTIME(haber.time)) and compare it toDATE(SYSDATE()) (sysdate will return the current database date):

$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"
);

You can also use the server date, like this:

AND DATE(FROM_UNIXTIME(haber.time)) = DATE(" . date('Y-m-d') . ")

People are also looking for solutions to the problem: exec - How to use pdftk in php while system functions is disabled

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.