Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/02/2010, 05:58
marinesky
 
Fecha de Ingreso: diciembre-2009
Ubicación: entre Ibiza y Barcelona :)
Mensajes: 92
Antigüedad: 14 años, 4 meses
Puntos: 3
Respuesta: Agrupar registros por años

Hola, yo ayer hice una pregunta parecia, pero yo queria que los registros me los mostra por mes.
Te dejo el codigo por si te sirve de algo.
Código PHP:
<?php 
session_start
(); 
require (
'db_connect.php'); 
require (
'functions.php'); 
connectar_imc(); 
?> 
<form action = "m5.php" method = "post"> 
<?php 
    
     
    
echo "<select name=\"year\" id=\"year\">"
    for(
$i=date(Y);$i>=2005;$i--) { 
        echo 
"<option value=\"".$i."\""
        if(
$_POST['year']==$i) echo " selected"
        echo 
">".$i."</option>"
    } 
    echo 
"</select>"
    echo 
"&nbsp;<input id=\"button\" name=\"enviar\" class=\"boton\" type=\"submit\" value=\"Ver\" "
?> 
    </form> 

<?php 
if( $_POST ){       
     
    echo 
"<table border='1'>"
    echo 
"<tr><td><b>Distribuidores</b></td><td><b>Enero</b></td><td><b>Febrero</b></td><td><b>Marzo</b></td><td><b>Abril</b></td><td><b>Mayo</b></td><td><b>Junio</b></td><td><b>Julio</b></td><td><b>Agosto</b></td><td><b>Septiembre</b></td><td><b>Octubre</b></td><td><b>Noviembre</b></td><td><b>Diciembre</b></td></tr>"


        
$query_dis=("SELECT id_distributor, distributor_name FROM distributor WHERE deleted_distributor = '0' order by distributor_name"); 
        
$result_dis=(mysql_query($query_dis)); 
         
        while (
$rows mysql_fetch_row($result_dis)){ 
            echo 
"<tr>"
        
            echo 
"<td>";          
            echo 
"<b>$rows[1]</b><br><br>"
            echo 
"</td>";
            
            
            for(
$i=1;$i<=12;$i++) { 
                if(
$i<10$mes="0".$i
                else 
$mes $i
                
$desde $_POST['year']."-".$mes."-01"
                
$hasta $_POST['year']."-".$mes."-31";     
        
                echo 
"<td>"
                echo 
"<b>ALTAS NO DEMO:</b><br>"
                
$query=("SELECT COUNT(client_name), registration_date, SUM(contracted_space/1073741824),id_distributor, id_pay_method, type_of_client, id_client FROM client WHERE id_distributor = '".$rows[0]."'  AND registration_date >= '".$desde."' and registration_date <= '".$hasta."' and demo_account = '0' order by count(client_name)"); 
                
$resultmysql_query($query) or die (mysql_error()); 
                while(
$row=mysql_fetch_array($result)) { 
                        if(
$row[0]==0){ 
                            echo 
"No hay altas en ".$mes."-".$_POST['year']."<br><br>"
                        }else{ 
                            echo   
"Clientes:&nbsp;" .$row[0]."<br>"
                            
"Espacio:&nbsp;".$row[2]."&nbsp;GB<br><br>";      
                        } 
                 
                }     
                echo 
"</td>";      
            }
            
            echo 
"</tr>"
        }        
        

?>
Un saludo y suerte.