Foros del Web » Programando para Internet » PHP »

Como ordeno titulo en php por fecha

Estas en el tema de Como ordeno titulo en php por fecha en el foro de PHP en Foros del Web. Hola tengo los siguiente en mi bd(mysql) LA TABLA POST TITULO DEL POST |||||||| FECHA mi post1 -----> 2013-03-24 23:32:10 mi post 2 -----> 2013-03-24 ...
  #1 (permalink)  
Antiguo 28/05/2013, 20:53
Avatar de thedenis  
Fecha de Ingreso: mayo-2013
Mensajes: 42
Antigüedad: 11 años
Puntos: 1
Pregunta Como ordeno titulo en php por fecha

Hola tengo los siguiente en mi bd(mysql) LA TABLA POST

TITULO DEL POST |||||||| FECHA

mi post1 -----> 2013-03-24 23:32:10
mi post 2 -----> 2013-03-24 23:32:10
mi post 3 -----> 2013-04-24 23:32:10
mi post 4 -----> 2013-04-24 23:32:10
mi post 5 -----> 2012-08-24 23:32:10
mi post 6 -----> 2012-08-24 23:32:10


Como podria hacer esto, lo eh visto en Blogspot o Wordpress

MES DE ABRIL DEL 2013 (2) POST

mi post1 2013-03-24 23:32:10
mi post 2 2013-03-24 23:32:10

MES DE MARZO DEL 2013 (2) POST

mi post 3 2013-04-24 23:32:10
mi post 4 2013-04-24 23:32:10

MES DE AGOSTO DEL 2008 (2) POST

mi post 5 2012-08-24 23:32:10
mi post 6 2012-08-24 23:32:10


Espero que me puedan ayudar aunque sea un poco del codigo o una pequeña ayudita
  #2 (permalink)  
Antiguo 29/05/2013, 02:05
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Como ordeno titulo en php por fecha

Sería algo así:

Código PHP:
Ver original
  1. <?php
  2. //Los valores
  3. $posts = array (
  4.         0 => '2013-03-22',
  5.         1 => '2013-03-24',
  6.         2 => '2013-03-24',
  7.         3 => '2013-04-24',
  8.         4 => '2013-04-25',
  9.         5 => '2012-08-25',
  10.         6 => '2012-08-26'
  11. );
  12.  
  13. for($i = 0; $i< count($posts); $i++){
  14.     //La fecha actual es al del registro actual
  15.     $fecha_actual = $posts[$i];
  16.     //LA fecha del registro anterior si existe, si no, leo la actual
  17.     $fecha_anterior = isset($posts[$i - 1])?$posts[$i - 1]:$posts[$i];
  18.     //Si es la misma fecha, se lista
  19.     if($fecha_actual == $fecha_anterior) echo $posts[$i] . '<br/>';
  20.     //Si no, se hace un echo con un titular
  21.     else {
  22.         echo '<h3>Siguiente dia</h3>';
  23.         echo $posts[$i] . '<br/>';
  24.     }
  25.    
  26. }
  27. ?>
Salu2
__________________
Fere libenter homines, id quod volunt, credunt.

Etiquetas: almacenar, php+bd
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:04.