NIKESLB 0 Posted June 5, 2011 Report Share Posted June 5, 2011 Olá, tenho um sistema de noticias e estou a tentar juntar as datas ou seja: Segunda, 25 Março Noticia 1 Noticia 2 Noticia 3 Domingo, 24 MArço Noticia 4 Sábado 23, Março Noticia 5 Noticia 6 Tenho uma função que reconhece o "hoje" e "ontem": function date_1($time) { setlocale(LC_TIME, 'pt_BR'); $date_d = date('d'); $date_objecto_d = date('d', $time); $date_m = date('m'); $date_objecto_m = date('m', $time); $date_y = date('Y'); $date_objecto_y = date('Y', $time); if($date_d == $date_objecto_d AND $date_m == $date_objecto_m AND $date_y == $date_objecto_y) { $date = strftime('Hoje ', $time); } elseif($date_d == ($date_objecto_d + 1) AND $date_m == $date_objecto_m AND $date_y == $date_objecto_y) { $date = strftime('Ontem ', $time); } else { $date = strftime(' %A %d %B %Y ', $time); } return $date; } Para chamar tudo: while ($dados = $return->fetch()) { if(date_1($dados['timestamp']) <> $date){ $date = mb_convert_encoding(ucwords(date_1($dados['timestamp'])), "UTF-8"); echo $date; } echo $dados['titulo']; } Bem na verdade localmente ele junta tudo de modo perfeito, mas quando ponho num servidor ele junta as notícias de "Hoje" "Ontem", mas após passado este tempo, ou seja torna-se em "$date = strftime(' %A %d %B %Y ', $time);" já não fica junto, e é escrito várias vezes a mesma data, ou seja: Segunda, 25 Março Noticia 1 Segunda, 25 MArço Noticia 2 Segunda25, Março Noticia 3 ...Pela vez de haver uma única data e as noticias ficar todas juntas: Segunda25, Março Noticia 1 Noticia 2 Noticia 3 Alguém sabe como posso resolver este problema? Link to post Share on other sites
overblue 0 Posted June 6, 2011 Report Share Posted June 6, 2011 Já experimentas-te isto? while ($dados = $return->fetch()) { $date = mb_convert_encoding(ucwords(date_1($dados['timestamp'])), "UTF-8"); if($data_anterior != $date) echo $date; $data_anterior = $date; echo $dados['titulo']; } Tu estavas a testar isto date_1($dados['timestamp']) com isto mb_convert_encoding(ucwords(date_1($dados['timestamp'])), "UTF-8") http://miguellopes.net/ | https://twitter.com/overblue Link to post Share on other sites
NIKESLB 0 Posted June 6, 2011 Author Report Share Posted June 6, 2011 Já percebi o meu erro. Finalmente já funciona bem. Muito obrigado Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now