Re: crear un pdf, el texto sacado de la bd Cita:
Iniciado por marybella Prueba asi: Código PHP: $link = mysql_pconnect('localhost','root',''); mysql_select_db('nombre_BD'); $query = "SELECT * FROM read WHERE campo LIKE '".$valor_de_variable_deseado."%'"; $result = mysql_query($query); $row = mysql_fetch_array($result);
por que no pones el codigo completo para ver en donde estan los errores del header, ok?? Me da el mismo error, el código es Código PHP: <? //=================================================================== //Raquerir la clase 'pdf' para la generación de ficheros pdf require('fphp/fpdf.php');
///////////////////////////////////////////////////////////// // Conectar a base de datos local ///////////////////////////////////////////////////////////// define('DB_USER', "root"); define('DB_PASSWORD', ""); define('DB_HOST', "127.0.0.1"); //conecta con servidor remoto define('DB_NAME', "ffextremo_cms");
///////////////////////////////////////////////////////////// // Conexión a mysql ///////////////////////////////////////////////////////////// $db_connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(Error_Mysql_Conect_DB());
////////////////////////////////////////////////////////////// // Seleccionar db ////////////////////////////////////////////////////////////// mysql_select_db (DB_NAME);
//===================================================================
class PDF extends FPDF { function PDF($orientation='l',$unit='mm',$format='A4') { //Llama al constructor de la clase padre $this->FPDF($orientation,$unit,$format); //Iniciacin de variables $this->B=0; $this->I=0; $this->U=0; }
function Header() { //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Movernos a la derecha $this->Cell(80); //T tulo $this->Cell(80,10,'Artículo en PDF',1,0,'C'); //Salto de línea $this->Ln(15); }
//Pie de página function Footer() { //Posicin: a 1,5 cm del final $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',8); //Número de pgina $this->Cell(0,10,'Página '.$this->PageNo().'/{nb}',0,0,'C'); }
//colorear la tabla y cargar datos function FancyTable($header) { //Colores, ancho de línea y fuente en negrita $this->SetFillColor(255,0,0); $this->SetTextColor(255); $this->SetDrawColor(128,0,0); $this->SetLineWidth(.3); $this->SetFont('','B'); //Cabecera $w=array(20,20,20,20,20,20,160); for($i=0;$i<count($header);$i++) $this->Cell($w[$i],7,$header[$i],1,0,'C',1); $this->Ln(); //Restauración de colores y fuentes $this->SetFillColor(224,235,255); $this->SetTextColor(0); $this->SetFont(''); //Datos $fill=0;
$Sql = "SELECT * FROM tbl_pruebas"; $Query = mysql_query($Sql); //Bucle para generar los datos while($row = mysql_fetch_array($Query)) { $this->Cell($w[0],6,$row['Campo1'],'LR',0,'C',$fill); $this->Ln(); $fill=!$fill;
} $this->Cell(array_sum($w),0,'','T'); }
} //==============================================================
//Iniciar documento PDF $pdf=new PDF(); $pdf->AliasNbPages(); //T tulos de las columnas $header=array(''); $pdf->SetFont('Arial','',10); $pdf->AddPage(); $pdf->FancyTable($header); $pdf->Output();
?> Con tu código sería (supongo) Código PHP: <? //=================================================================== //Raquerir la clase 'pdf' para la generación de ficheros pdf require('fphp/fpdf.php');
///////////////////////////////////////////////////////////// // Conectar a base de datos local ///////////////////////////////////////////////////////////// define('DB_USER', "root"); define('DB_PASSWORD', ""); define('DB_HOST', "127.0.0.1"); //conecta con servidor remoto define('DB_NAME', "ffextremo_cms");
///////////////////////////////////////////////////////////// // Conexión a mysql ///////////////////////////////////////////////////////////// $db_connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(Error_Mysql_Conect_DB());
////////////////////////////////////////////////////////////// // Seleccionar db ////////////////////////////////////////////////////////////// mysql_select_db (DB_NAME);
//===================================================================
class PDF extends FPDF { function PDF($orientation='l',$unit='mm',$format='A4') { //Llama al constructor de la clase padre $this->FPDF($orientation,$unit,$format); //Iniciacin de variables $this->B=0; $this->I=0; $this->U=0; }
function Header() { //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Movernos a la derecha $this->Cell(80); //T tulo $this->Cell(80,10,'Artículo en PDF',1,0,'C'); //Salto de línea $this->Ln(15); }
//Pie de página function Footer() { //Posicin: a 1,5 cm del final $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',8); //Número de pgina $this->Cell(0,10,'Página '.$this->PageNo().'/{nb}',0,0,'C'); }
//colorear la tabla y cargar datos function FancyTable($header) { //Colores, ancho de línea y fuente en negrita $this->SetFillColor(255,0,0); $this->SetTextColor(255); $this->SetDrawColor(128,0,0); $this->SetLineWidth(.3); $this->SetFont('','B'); //Cabecera $w=array(20,20,20,20,20,20,160); for($i=0;$i<count($header);$i++) $this->Cell($w[$i],7,$header[$i],1,0,'C',1); $this->Ln(); //Restauración de colores y fuentes $this->SetFillColor(224,235,255); $this->SetTextColor(0); $this->SetFont(''); //Datos $fill=0; $id = $_GET['id']; $link = mysql_pconnect('localhost','root',''); mysql_select_db('ffextremo_cms'); $query = "SELECT * FROM read WHERE id LIKE '".$id."%'"; $result = mysql_query($query); //Bucle para generar los datos while($row = mysql_fetch_array($result)) { $this->Cell($w[0],6,$row['Campo1'],'LR',0,'C',$fill); $this->Ln(); $fill=!$fill;
} $this->Cell(array_sum($w),0,'','T'); }
} //==============================================================
//Iniciar documento PDF $pdf=new PDF(); $pdf->AliasNbPages(); //T tulos de las columnas $header=array(''); $pdf->SetFont('Arial','',10); $pdf->AddPage(); $pdf->FancyTable($header); $pdf->Output();
?> |