Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/09/2006, 15:43
Avatar de ing_aprendiz
ing_aprendiz
 
Fecha de Ingreso: septiembre-2005
Mensajes: 136
Antigüedad: 18 años, 8 meses
Puntos: 0
Pregunta consulta mysql para realizar calculo entre columnas

hola amigos foreros una vez más requiero de su ayuda, resulta que tengo el siguiente código:

Código PHP:
<?php
$conex 
mysql_connect("localhost""root""");
$conectarsemysql_select_db("kansei"$conex);
//$conectarse= mysql_select_db("apsoluti_kansei", $conex);
//if (!isset($_REQUEST["id_matriz"])) { $id_matriz=45;}

$sql =  "SELECT rt.descripcion, rt.id_rtecnico".
        
" FROM rtecnico rt, matriz m".
        
" WHERE m.id_matriz=rt.id_matriz AND m.id_matriz=$id_matriz";
        
$sql2 "SELECT rc.descripcion, rc.importancia, rc.id_rcliente".
        
" FROM rcliente rc, matriz m".
        
" WHERE rc.id_matriz=m.id_matriz AND m.id_matriz=$id_matriz";
        
$query mysql_query($sql);
$query2 mysql_query($sql2);

$num mysql_num_rows($query);
$num2 mysql_num_rows($query2);

require(
'fpdf.php');
//require('pdf/fpdf.php');
require('rotation.php');

class 
PDF extends PDF_Rotate
{
    function 
RotatedText($x,$y,$txt,$angle)
    {
    
$this->Rotate($angle,$x,$y);
    
$this->Text($x,$y,$txt);
    
$this->Rotate(0);
    }
    
    function 
Header()
    {
    
//Logo
    
$this->Image('img_r1_c1.jpg',10,8,250);
    
//Arial bold 15
    
$this->SetFont('Arial','B',15);
    }

//Pie de página
    
function Footer()
    {
    
//Posición: a 1,5 cm del final
    
$this->SetY(-15);
    
//Arial italic 8
    
$this->SetFont('Arial','I',8);
    
//Número de página
    
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
}

$pdf=new PDF('L','mm','Letter');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',8);
$pdf->SetDrawColor(102,153,204);
$pdf->SetLineWidth(.0);
$pdf->Ln(2);
$pdf->Cell(20,10,'',0,0,'C');
$pdf->RotatedText(75,60,'Prioridad',90); 
if (
$num 0)
{
    
$i=0;
    
$x=86;
    while (
$row mysql_fetch_array($query)) 
    {    
            
$pdf->RotatedText($x,60,$row["descripcion"],90);
            
$rt[$i] = $row[1];
            
$i++;
            
$x$x+10;
    }
    
$pdf->SetFont('','B');
    
$pdf->RotatedText($x,60,'V. Cliente',90);
    
$pdf->RotatedText($x+10,60,'V. Comp.',90);
    
$pdf->Ln(50);
    
$pdf->SetFont('Arial','',8);    
    if(
$num2 0)    {
        while (
$row2 mysql_fetch_array($query2)) 
        {
            
$pdf->Cell(60,10,$row2["descripcion"],1,0,'C'); 
            
$pdf->Cell(10,10,$row2["importancia"],1,0,'C');
            
$total=0;
        foreach(
$rt as $newrt)
        {
            [
B]$sql3 " SELECT rtrc.valor, rc.importancia".
                    
" FROM rtecnico_rcliente rtrc, rcliente rc".
                    
" WHERE rtrc.id_rtecnico='$newrt' AND rtrc.id_rcliente='".$row2["id_rcliente"]."'
                    and rc.id_rcliente='"
.$row2["id_rcliente"]."' 
                    AND rtrc.id_matriz=$id_matriz"
;[/B]                    
            
$query3 mysql_query($sql3);
            
$row3 mysql_fetch_array($query3);
            if(
$row3["valor"]=="")
            {
                
$pdf->Cell(10,10,"-",1,0,'C');
            }else
            {
                
$pdf->Cell(10,10,$row3["valor"],1,0,'C');
                
$suma=$row3["valor"]*$row3["importancia"];
                
$total=$total $suma;
            }
        }
        
        
$sql4 " SELECT rc.vlr_cliente, rc.vlr_competidor".
                
" FROM rcliente rc".
                
" WHERE rc.id_rcliente='".$row2["id_rcliente"]."' AND rc.id_matriz=$id_matriz";
            
$query4 mysql_query($sql4);
            while(
$row4 mysql_fetch_array($query4))
            {
                if(
$row4["vlr_cliente"]==""){
                    
$pdf->Cell(10,10,"ss",1,0,'C');
                }else{
                    
$pdf->Cell(10,10,$row4["vlr_cliente"],1,0,'C');
                }
        
            if(
$row4["vlr_competidor"]==""){
                    
$pdf->Cell(10,10,"-",1,0,'C');
                }else{
                    
$pdf->Cell(10,10,$row4["vlr_competidor"],1,1,'C');        
                }
            }
        }
    }        
    
    
$titulos = array("Situación Empresa""Situación Empresa Competidora""Benchmark");
    
$campos = array("sit_empresa""sit_competencia""benchmark");
    for(
$t=0;$t<count($titulos);$t++)
    {
        
$pdf->Cell(70,10,$titulos[$t],1,0,'C');
        foreach(
$rt as $newrt)
        {
                
$sql5 "SELECT rt.".$campos[$t].
                    
" FROM rtecnico rt".
                    
" WHERE rt.id_rtecnico='$newrt' and rt.id_matriz='$id_matriz'";
                
$query5 mysql_query($sql5);
                
$num5 mysql_num_rows($query5);
                if(
$num5>0)
                {
                    while(
$row mysql_fetch_array($query5))
                    {
                        
$pdf->Cell(10,10,$row[0],1,0,'C');
                    }
                }
        }
        
$pdf->Cell(10,10,'',1,0,'C');
        
$pdf->Cell(10,10,'',1,1,'C');        
    }
        
$pdf->cell(70,10,'Valor Absoluto',1,0,'C');
        
$pdf->cell(10,10,$total,1,0,'C');
        
//$this->Ln(2);        
        //$pdf->cell(70,10,'Valor Relativo',1,0,'C');
}
$pdf->Output();
?>
este código genera un reporte en pdf, debo hayar unos calculos entre las columnas de la siguiente manera:

tengo dos valores uno es prioridad y el otro es valor, resulta que tengo que hayar un total por cada columna y este total es igual a multiplicar prioridad * valor (en la primera fila) + prioridad por valor (en la segunda fila) y asi sicecivamente, luego para la segunda columna prioridad * valor (primera fila) + prioridad * valor (segunda fila) y asi con todas las filas y columnas que hayan en la tabla hayando un valor difrente para cada columna.

el código que acabo de colocar me hace el calculo pero me da un solo total pues me multiplica el valor de la prioridad en cada una de las filas y las suma y me da un solo total, lo cual estaría mal pues debe darme un valor difrente para cada columna.

espero me haya hecho entender es un poco complicado de explicar.

chao

agradezco cualquiera de sus aportes que me den nuevas ideas para solucionar el problema.