Foros del Web » Programando para Internet » PHP »

Agrupar por cliente y ultimo registro

Estas en el tema de Agrupar por cliente y ultimo registro en el foro de PHP en Foros del Web. Les explico un poco compañeros, tengo una tabla de antivirus y desearia que cada usuario se mostrara con nombre, apellidos, antivirus..... y que sea el ...
  #1 (permalink)  
Antiguo 29/12/2009, 19:25
 
Fecha de Ingreso: agosto-2009
Mensajes: 96
Antigüedad: 14 años, 7 meses
Puntos: 1
Agrupar por cliente y ultimo registro

Les explico un poco compañeros, tengo una tabla de antivirus y desearia que cada usuario se mostrara con nombre, apellidos, antivirus..... y que sea el ultimo registro, agrupando por cliente.

Uso php+sql

Gracias

Código PHP:
 <?php
  $cambiarfecha
;
 
$BD mysql_connect("localhost""root");
mysql_select_db("basededatos",$BD);
$consulta "SELECT * from antiviruspanda ORDER BY ID_ANTIVIRUS DESC limit 0,5";
$resultat=mysql_query($consulta$BD);
if (
$columna mysql_fetch_array($resultat)){

      function 
dateadd1($date$dd=0$mm=0$yy=0$hh=0$mn=0$ss=0){
   
          
$date_r getdate(strtotime($date));

          
$date_result date("d-m-Y"mktime(($date_r["hours"]+$hh),($date_r["minutes"]+$mn),($date_r["seconds"]+$ss),($date_r["mon"]+$mm),($date_r["mday"]+$dd),($date_r["year"]+$yy)));

          return 
$date_result;

      }
function 
dateadd2($date$yy=0){
    
$date_r getdate(strtotime($date));
    
$date_result date('d-m-Y'mktime(0,0,0,($date_r['mon']),($date_r['mday']),($date_r['year']+$yy)));
    return 
$date_result;
}
echo 
"<p><img src='ULTIMOS_5_REGISTROS.gif' width='230' height='48' align='left'><p>";
echo 
"<table border='0'>";
echo 
"<tr>";
echo 
"<table border='0'>";
echo 
"<tr><th></th><th></th><th></th><th></th><th></th><th></th><th><img src='tabla_fecha.jpg'></th><th><img src='tabla_nombre.jpg'></th><th><img src='tabla_apellidos.jpg'></th><th><img src='tablas_poblacion.jpg'></th><th><img src='tabla_antivirus.jpg'></th><th><img src='tabla_licencias.jpg'></th></tr>";
     
do{
echo 
"<tr>";
echo 
"<th><a href='Baixa_Antivirus_Particular.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='eliminar.gif' width='20' height='20' alt='eliminar' border='0'></a></th>";
echo 
"<th><a href='Form_Modifica_Antivirus_Particulares.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='modificar.png' width='20' height='20' alt='modifica' border='0'></a></th>";
echo 
"<th><a href='Antivirus_Particulares_Panda_Info.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='mas.png' width='20' height='20' alt='+info' border='0'></a></th>";
echo 
"<th><a href='Descarga_Particulares_Panda1.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='descarga.png' width='20' height='20' alt='descarga' border='0'></a></th>";
echo 
"<th><a href='./EMAIL_PANDA/mailattach.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='email.png' width='20' height='20' alt='email' border='0'></a></th>";
$fecha $columna['FECHA']; //mes/dia/año
  
$fecha_actualizada dateadd1($fecha,0,0,1); // suma 1 dia a la fecha

$hoy date("d-m-Y");
if(!empty(
$columna['NUMCLIENTE'])){
    echo 
'<th><img src="verde.gif" alt="ACTIVADO" border="0">';
    if(
strtotime(dateadd1($fecha_actualizada,1)) <= strtotime($hoy)){
        echo 
"<img src='caducado.gif' alt='CADUCADO' border='0'>";
    }
}else{
    echo 
'<th><img src="rojo.gif" alt="SIN ACTIVAR" border="0">';
}  
echo 
"<td>".$columna['FECHA'];
echo 
"<td>".$columna['NOMBRE'];
echo 
"<td>".$columna['APELLIDOS'];
echo 
"<td>".$columna['POBLACION'];
echo 
"<td>".$columna['ANTIVIRUS'];
echo 
"<td>".$columna['NUMLICENCIAS'];

echo 
"</tr>";
} while (
$columna mysql_fetch_array($resultat));
echo 
"</table>";
} else echo (
"");

 
$BD mysql_connect("localhost""root");
mysql_select_db("basededatos",$BD);
$consulta "SELECT * from antiviruspanda order by id_antivirus"
$resultat=mysql_query($consulta$BD);
if (
$columna mysql_fetch_array($resultat)){
echo 
"<p><img src='TODOS_LOS_REGISTROS.gif' width='230' height='48' align='CENTER'><p>";
echo 
"<table border='0'>";
echo 
"<tr>";
echo 
"<table border='0'>";
echo 
"<tr><th></th><th></th><th></th><th></th><th></th><th></th><th><img src='tabla_fecha.jpg'></th><th><img src='tabla_nombre.jpg'></th><th><img src='tabla_apellidos.jpg'></th><th><img src='tablas_poblacion.jpg'></th><th><img src='tabla_antivirus.jpg'></th><th><img src='tabla_licencias.jpg'></th></tr>";
     
do{
echo 
"<tr>";
echo 
"<th><a href='Baixa_Antivirus_Particular.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='eliminar.gif' width='20' height='20' alt='eliminar' border='0'></a></th>";
echo 
"<th><a href='Form_Modifica_Antivirus_Particulares.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='modificar.png' width='20' height='20' alt='modifica' border='0'></a></th>";
echo 
"<th><a href='Antivirus_Particulares_Panda_Info.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='mas.png' width='20' height='20' alt='+info' border='0'></a></th>";
echo 
"<th><a href='Descarga_Particulares_Panda1.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='descarga.png' width='20' height='20' alt='descarga' border='0'></a></th>";
echo 
"<th><a href='Email_Panda.php?ID_ANTIVIRUS=".$columna['ID_ANTIVIRUS']."'><img src='email.png' width='20' height='20' alt='email' border='0'></a></th>";
$fecha $columna['FECHA']; //mes/dia/año
  
$fecha_actualizada dateadd1($fecha,0,0,1); // suma 1 dia a la fecha

$hoy date("d-m-Y");
if(!empty(
$columna['NUMCLIENTE'])){
    echo 
'<th><img src="verde.gif" alt="ACTIVADO" border="0">';
    if(
strtotime(dateadd1($fecha_actualizada,1)) <= strtotime($hoy)){
        echo 
"<img src='caducado.gif' alt='CADUCADO' border='0'>";
    }
}else{
    echo 
'<th><img src="rojo.gif" alt="SIN ACTIVAR" border="0">';
}  
echo 
"<td>".$columna['FECHA'];
echo 
"<td>".$columna['NOMBRE'];
echo 
"<td>".$columna['APELLIDOS'];
echo 
"<td>".$columna['POBLACION'];
echo 
"<td>".$columna['ANTIVIRUS'];
echo 
"<td>".$columna['NUMLICENCIAS'];


echo 
"</tr>";
} while (
$columna mysql_fetch_array($resultat));
echo 
"</table>";
} else echo (
"<img src='vacia.png' width='40' height='40' alt='vacia'>La lista esta vacia");

?>
  #2 (permalink)  
Antiguo 29/12/2009, 20:58
 
Fecha de Ingreso: enero-2008
Mensajes: 381
Antigüedad: 16 años, 2 meses
Puntos: 19
Respuesta: Agrupar por cliente y ultimo registro

deberias poner el esquema de la tabla y/o base de datos si quieres que te ayudemos
  #3 (permalink)  
Antiguo 03/01/2010, 19:23
 
Fecha de Ingreso: agosto-2009
Mensajes: 96
Antigüedad: 14 años, 7 meses
Puntos: 1
Respuesta: Agrupar por cliente y ultimo registro

lo que quiero es que se vea el ultimo registro agrupado por clientes y que despues yo pondre un boton que ponga ver todo el historial y que me muestre todos los antivirus del cliente.La tabla de clientes y la de antivirus no tiene ninguna relacion pero se guarda la informacion de la tabla de antivirus se guara nombre de cliente y dni.
  #4 (permalink)  
Antiguo 03/01/2010, 19:33
 
Fecha de Ingreso: enero-2008
Mensajes: 381
Antigüedad: 16 años, 2 meses
Puntos: 19
Respuesta: Agrupar por cliente y ultimo registro

Pon el esquema de tabla y un ejemplo y expliques lo que quieres basandote en ese ejemplo y nombrando las columnas/tablas definidas en el, no querras que descifre todo leyendo el PHP.

Segun como lo tengas organizado algo como:

Tabla clientes:

ID | Nombre | Apellido | Antivirus | etc etc
1 Juan Perez Norton
2 Pablo Felipe Kaspersky

¿entiendes lo que pido?
  #5 (permalink)  
Antiguo 10/01/2010, 12:57
 
Fecha de Ingreso: agosto-2009
Mensajes: 96
Antigüedad: 14 años, 7 meses
Puntos: 1
Respuesta: Agrupar por cliente y ultimo registro

LO TENGO ASI:

ID | FECHA | NOMBRE | APELLIDOS | POBLACION | ANTIVIRUS | NUMERO LICENCIAS | DIRECCION | DNI |

Y lo tengo organizado en 4 tablas diferentes una para los antivirus panda particulares, panda empresas, nod32 particulares, nod32 empresas.
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 22:45.