Foros del Web » Programando para Internet » PHP »

Notice: Undefined offset en tcpdf

Estas en el tema de Notice: Undefined offset en tcpdf en el foro de PHP en Foros del Web. Buenas noches. He echo varias reportes en pdf usando la libreria TCPDF. Todo me funcionaba muy bien hasta que cambie de MySQL a MySQLI. Lo ...
  #1 (permalink)  
Antiguo 18/12/2014, 21:13
 
Fecha de Ingreso: diciembre-2014
Ubicación: Cali
Mensajes: 20
Antigüedad: 9 años, 4 meses
Puntos: 0
Pregunta Notice: Undefined offset en tcpdf

Buenas noches. He echo varias reportes en pdf usando la libreria TCPDF. Todo me funcionaba muy bien hasta que cambie de MySQL a MySQLI. Lo que antes me funcinaba con las consultas MySQL ya no me funciona: Me aparece el siguiente mensaje:
Notice: Undefined offset para o , 1,2,3...

en estas líneas

Código PHP:
    $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], 6utf8_encode($row[2]), 'LR'0'L'$fill);
            
$this->Cell($w[3], 6$row[3], 'LR'0'L'$fill);
            
$this->Cell($w[4], 6number_format($row[4]), 'LR'0'R'$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], 7$row[7], 'LR'0'L'$fill); 
Por favor me pueden ayudar. Este mismo mensaje me lo muestra en las paginas php y he solucionado colocando el campo. $fila[0] lo cambio por $fila['nombre_campo']. Pero en el archivo que convierte a pdf no lo hace.
me sale: TCPDF ERROR: Some data has already been output, can't send PDF file

Anexo código

Código PHP:
require_once('/config/eng.php');
require_once(
'../tcpdf/tcpdf.php');
class 
MYPDF extends TCPDF {

    
// Colored table
    
public function ColoredTable($header,$data) {
        
// Colors, line width and bold font
        
$this->SetFillColor(25500);
        
$this->SetTextColor(255);
        
$this->SetDrawColor(12800);
        
$this->SetLineWidth(0.3);
        
$this->SetFont('''B');
        
// Header
        
$w = array(13183240185020,20);
        
$num_headers count($header);
        for(
$i 0$i $num_headers; ++$i) {
          
$this->Cell($w[$i], 7$header[$i], 10'C'1);
        }
        
$this->Ln();
        
// Color and font restoration
        
$this->SetFillColor(224235255);
        
$this->SetTextColor(0);
        
$this->SetFont('');
        
// Data
        
$fill 0;
        foreach(
$data as $row) {
            
$this->Cell($w[0], 6$row['codcomuna'], 'LR'0'L'$fill);
            
$this->Cell($w[1], 6$row['nrodoc'], 'LR'0'L'$fill);
            
$this->Cell($w[2], 6utf8_encode($row['nomcor']), 'LR'0'L'$fill);
            
$this->Cell($w[3], 6$row['apecor'], 'LR'0'L'$fill);
            
$this->Cell($w[4], 6number_format($row['vofcor']), 'LR'0'R'$fill);
            
$this->Cell($w[5], 6$row['dircor'], 'LR'0'L'$fill);
            
$this->Cell($w[6], 6$row['telcor'], 'LR'0'L'$fill);
            
$this->Cell($w[7], 7$row['celcor'], 'LR'0'L'$fill);
            
$this->Ln();
            
$fill=!$fill;
        }
        
$this->Cell(array_sum($w), 0'''T');
    }
}

// create new PDF document
$pdf = new MYPDF('L'PDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Jordi Girones');
$pdf->SetTitle('TCPDF Tutorial - TCPDF + MySQL');
$pdf->SetSubject('TCPDF Tutorial - TCPDF + MySQL');
$pdf->SetKeywords('TCPDF, PDF, example, test, mysql');

// set default header data
$pdf->SetHeaderData(''PDF_HEADER_LOGO_WIDTH,PDF_HEADER_TITLE.'''LISTADO DE COORDINADORES --TOTAL VOTOS OFRECIDOS: '.$totalv);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN''PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA''PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica'''7);

// add a page
$pdf->AddPage();

//Column titles
$header = array('COMUNA''CEDULA''NOMBRE''APELLIDO''V. OFREC''DIRECCION''TELEFONO''CELULAR');

//Data loading
$query="SELECT coordinazona.codcomuna, coordinador.nrodoc, coordinador.nomcor, coordinador.apecor, coordinador.vofcor, coordinador.dircor, coordinador.telcor, coordinador.celcor
FROM coordinazona INNER JOIN coordinador ON coordinazona.codcor = coordinador.codcor ORDER BY coordinazona.codcomuna ASC"
;
$rs=$conexion->query($query);
while(
$rw mysqli_fetch_assoc($rs)){
        
$data[] = $rw;
 }


// print colored table
$pdf->ColoredTable($header$data);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('listado01.pdf''I'); 
  #2 (permalink)  
Antiguo 19/12/2014, 14:31
Colaborador
 
Fecha de Ingreso: mayo-2008
Ubicación: $MX['VZ']['Xalapa']
Mensajes: 3.005
Antigüedad: 16 años
Puntos: 528
Respuesta: Notice: Undefined offset en tcpdf

Si te da el error undefined offset en $row[0], quiere decir que $row no contiene un valor en la posición 0, por lo que tienes que revisar que tu consulta devuelva los datos correctos, antes de hacer el pdf, muestra el resultado de tu consulta en pantalla.
  #3 (permalink)  
Antiguo 20/12/2014, 12:34
 
Fecha de Ingreso: julio-2010
Mensajes: 275
Antigüedad: 13 años, 10 meses
Puntos: 21
Respuesta: Notice: Undefined offset en tcpdf

prueba esto, yo tambien soy nuevo con mysqli
Código PHP:
Ver original
  1. $mysqli = new mysqli(SERVIDOR, USUARIO, CLAVE, BASEDEDATOS);
  2. if ($mysqli->connect_error) {
  3.     die('Error de Conexión (' . $mysqli->connect_errno . ') '
  4.             . $mysqli->connect_error);
  5. }
  6. //aqui va la consulta SQL
  7. $resultado = $mysqli->query($query);
  8. while ($fila = $resultado->fetch_assoc()) {
  9.     data[]=$fila;
  10. }

Etiquetas: mysql, notice, offset, select, tcpdf, undefined
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 13:15.