Ver Mensaje Individual
  #7 (permalink)  
Antiguo 25/05/2009, 00:34
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Sumar datos de dos tablas.

Aqui esta el completo ahora si este codigo verifica las dos tablas y te trae la información que estas pidiendo


Código PHP:
$sql "SELECT count(*) as Rows, idusuario FROM tabla1 GROUP BY idusuario";
$r mysql_query($sql) or die(mysql_error());

$sql2 "SELECT count(*) as Rows, idusuario FROM tabla2 GROUP BY idusuario";
$r2 mysql_query($sql2) or die(mysql_error());

$setBool false;
while(
$row mysql_fetch_assoc($r)){
    while(
$row2 mysql_fetch_assoc($r2)){
        if(
$row["idusuario"] == $row2["idusuario"]){
            echo 
$row["idusuario"]." = ".($row["Rows"]+$row2["Rows"])."<br />";
            
$setBool true;
        }
    }
    
mysql_data_seek($r2,0);
    
    if(
$setBool == false){
        echo 
$row["idusuario"]." = ".$row["Rows"]."<br />";
    }
    
$setBool false;
}
mysql_data_seek($r,0);

$setBool2 true;
while(
$row3 mysql_fetch_assoc($r2)){
    while(
$row4 mysql_fetch_assoc($r)){
        if(
$row3["idusuario"] == $row4["idusuario"]){
            
$setBool2 false;
        }
    }
    
mysql_data_seek($r,0);
    
    if(
$setBool2){
        echo 
$row3["idusuario"]." = ".$row3["Rows"]."<br />";
    }
    
$setBool2 true;