Ver Mensaje Individual
  #6 (permalink)  
Antiguo 24/02/2010, 07:49
Avatar de lolitashu
lolitashu
 
Fecha de Ingreso: enero-2010
Ubicación: Chile / Santiago / Quilicura
Mensajes: 50
Antigüedad: 14 años, 3 meses
Puntos: 2
Respuesta: Agrupar registros por años

Cambia las variables y listo

Código PHP:
Ver original
  1. <?php
  2. require "conecta.php";
  3.  
  4. $anhos="SELECT * FROM noticia GROUP BY year ORDER BY year DESC";
  5. $resanhos = mysql_query($anhos,$dblink);
  6.          
  7. echo "<table border='1'>";       
  8. while($extrae1 = mysql_fetch_array($resanhos))
  9. {  
  10.     echo "<tr><td colspan='4'>Registros del ".$extrae1["year"]."</td></tr>";
  11.    
  12.     $registros="SELECT * FROM noticia WHERE year = ".$extrae1["year"]." ORDER BY year DESC";
  13.     $resregistros = mysql_query($registros,$dblink);
  14.    
  15.     while($extrae2 = mysql_fetch_array($resregistros))
  16.     {
  17.     echo "<tr>";
  18.     echo "<td>".$extrae2['id']."</td>";                                        
  19.     echo "<td>".$extrae2['year']."</td>";
  20.     echo "<td>".$extrae2['titulo']."</td>";
  21.     echo "<td><a href='codigo?id=".$extrae2['id']."'.php><u>Ver</u></a></td>";
  22.     echo "</tr>";
  23.     }
  24. }
  25. echo "</table><br>";
  26.  
  27. mysql_close($dblink);
  28. ?>