PHP - insertas datos en celdas

 
Vista:

insertas datos en celdas

Publicado por Montses (27 intervenciones) el 20/04/2007 20:36:08
Hola !!!!, mi pregunta es la sig, estoy ocupando la libreria Fpdf para la generacion de pdf desde php, ya tengo mi tabla hecha, con un ciclo como el siguiente.

foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'L',$fill);
$this->Cell($w[4],6,$row[4],'LR',0,'L',$fill);
$this->Cell($w[5],6,$row[5],'LR',0,'L',$fill);
$this->Cell($w[6],6,$row[6],'LR',0,'L',$fill);
$this->Cell($w[7],6,$row[7],'LR',0,'L',$fill);
$this->Cell($w[8],6,$row[8],'LR',0,'L',$fill);
$this->Cell($w[9],6,$row[9],'LR',0,'L',$fill);

$this->Ln();
$fill=!$fill;
}

lo que necesito es imprimir el contenido de una variable dentro de una celda determinada, pero si la incluyo dentro del ciclo anterior me la pone en toda la columan y solo lo quiero en una determinada celda, tienen aulga idea de como podria hacer eso ???
mil gracias por su ayuda de antemano

SMILE!!!!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

RE:insertas datos en celdas

Publicado por Yamil Bracho (888 intervenciones) el 20/04/2007 22:44:56
No lo he pobado pero piendo que pudieras usar el metoso SetX()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:insertas datos en celdas

Publicado por BlueStalker (55 intervenciones) el 23/04/2007 18:17:00
Hola!!!!

Esta clase es de mucha utilidad xD en tu caso:

<?php
require('fpdf.php');

class PDF_MySQL_Table extends FPDF
{
var $ProcessingTable=false;
var $aCols=array();
var $TableX;
var $HeaderColor;
var $RowColors;
var $ColorIndex;

function Header()
{
//Print the table header if necessary
if($this->ProcessingTable)
$this->TableHeader();
}

function TableHeader()
{
$this->SetFont('Arial','B',12);
$this->SetX($this->TableX);
$fill=!empty($this->HeaderColor);
if($fill)
$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
$this->Ln();
}

function Row($data)
{
$this->SetX($this->TableX);
$ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]);
if($fill)
$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
$this->Ln();
$this->ColorIndex=1-$ci;
}

function CalcWidths($width,$align)
{
//Compute the widths of the columns
$TableWidth=0;
foreach($this->aCols as $i=>$col)
{
$w=$col['w'];
if($w==-1)
$w=$width/count($this->aCols);
elseif(substr($w,-1)=='%')
$w=$w/100*$width;
$this->aCols[$i]['w']=$w;
$TableWidth+=$w;
}
//Compute the abscissa of the table
if($align=='C')
$this->TableX=max(($this->w-$TableWidth)/2,0);
elseif($align=='R')
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
else
$this->TableX=$this->lMargin;
}

function AddCol($field=-1,$width=-1,$caption='',$align='L')
{
//Add a column to the table
if($field==-1)
$field=count($this->aCols);
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
}

function Table($query,$prop=array())
{
//Issue query
$res=mysql_query($query) or die('Error: '.mysql_error()."<BR>Query: $query");
//Add all columns if none was specified
if(count($this->aCols)==0)
{
$nb=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Retrieve column names when not specified
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
//Handle properties
if(!isset($prop['width']))
$prop['width']=0;
if($prop['width']==0)
$prop['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop['align']))
$prop['align']='C';
if(!isset($prop['padding']))
$prop['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop['padding'];
if(!isset($prop['HeaderColor']))
$prop['HeaderColor']=array();
$this->HeaderColor=$prop['HeaderColor'];
if(!isset($prop['color1']))
$prop['color1']=array();
if(!isset($prop['color2']))
$prop['color2']=array();
$this->RowColors=array($prop['color1'],$prop['color2']);
//Compute column widths
$this->CalcWidths($prop['width'],$prop['align']);
//Print header
$this->TableHeader();
//Print rows
$this->SetFont('Arial','',11);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
}
?>

y se llama de esta forma:

<?php
define('FPDF_FONTPATH','font//');
require('mysql_table.php');
class PDF extends PDF_MySQL_Table
{
function Header()
{
$this->Ln(5);
$this->SetFont('Arial','',15);
$this->Cell(0,4,'TITULO',0,1,'R');
$this->Ln(10);
$this->Ln(10);
$logo="tulogo.jpg"; //si kieres
$this->Image($logo, 5, 5, 0, 0);
$this->Ln(3);
parent::Header();
}
}
mysql_connect('localhost','user','pass');
mysql_select_db('base de datos');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();

$pdf->AddCol('a',20,'a','L'); //tantas veces como columnas necesites o tengas
$pdf->AddCol('b',20,'b','L');

$prop=array('HeaderColor'=>array(200,200,200), //color de la cabeza de la tabla
'color1'=>array(240,240,245), //color de la fila impar
'color2'=>array(255,255,255), // color de la fila par
'padding'=>1);
$pdf->Table('Sentencia select con la ke rellenas la tabla, debe coincidir el nombre de campo con el que pones en la funcion AddCol y listo',$prop);
$pdf->Output();
?>

Espero te sirva de Algo, aun que solo sea para darte una idea xD

Salu2 y suerte xD
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:insertas datos en celdas

Publicado por Montses (27 intervenciones) el 24/04/2007 17:46:08
gracias, solo una pregunta en la funcion AddCol, es que parte se coloca el nombre de mi campo, gracias !!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:insertas datos en celdas

Publicado por BlueStalker (55 intervenciones) el 24/04/2007 19:24:09
Hola!!!!

AddCol(Nombre del campo (el mismo de la consulta),tamaño del campo (o celda),Titulo de la columna (Header),alineacion (centrado, izquierda, derecha))

Creo ke eso es todo

Salu2 y Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar