Hi,

I'm trying to do a list of news, but i only want today's news and news from the past what i don't want is future news(tomorrow,...).

So i'm doing if the date <=$curdate, but future news appear anyway, can you help me, plz?

<?php    
                        $curdate = date("d/m/Y");   

                        $row_noticias = getRows("SELECT n.id, str_to_date(n.data, '%d/%m/%Y') AS date, nl.id_noticia, nl.titulo, nl.descricao, nl.resumo 
                                                FROM `noticias` as n, `noticias_lang` as nl 
                                                WHERE n.id = nl.id_noticia AND
                                                nl.lang='$current_lang' AND n.visivel=1 AND nl.visivel=1
                                                ORDER BY date DESC LIMIT 1");

                        foreach($row_noticias as $key => $noticia)
                            {       
                                echo $noticia['date'] < $curdate;
                                die;

                                $query_data=mysql_query("SELECT * FROM noticias WHERE data='".$curdate."'") or die(mysql_error());
                                $data=mysql_fetch_assoc($query_data);

                                if ($data['data'] < $curdate )
                                {
                                    echo "<label>".formatdate($data['data'])."</label>";
                                    echo "<a href='".$current_lang."/noticia/".$noticia['id_noticia']."'>".get_substr($noticia['resumo'], 140)."</a>";
                                }
                            }
                ?>
Member Avatar for diafol

Ordering by d/m/Y won't work - you need to order by Y-m-d.

Also comparison by d/m/Y won't work

ALso where do you filter out the future date in the original WHERE clause? Can't see why you've got sql query in a loop here - can't you use a JOIN?

If you need to show d/m/Y, IMO, store everything and order/compare by Y-m-d or even unix timestamp and only change to d/m/Y for screen display.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.