Question

Hi this my php code :

<?php require_once('tcpdf/config/lang/eng.php'); ?>
    <?php require_once('tcpdf/tcpdf.php'); ?>
    <?php include_once("class/class_productos.php"); ?>
    <?php include_once("class/class_clientes.php"); ?>
    <?php include_once("class/class_img_gen.php"); ?>
    <?php include_once("class/class_acros.php"); ?>   // here is MY DB CONNECTION
    <?php 

    class MYPDF extends TCPDF {
        //Page header
        public function Header() {
            $auto_page_break = $this->AutoPageBreak;
            $this->SetAutoPageBreak(false, 0);
            $img_file = 'img/pdf_fondo.jpg';
            $this->Image($img_file, $x=0, $y=0, $w=210, $h=297, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0);
            $this->SetAutoPageBreak($auto_page_break);
        }
    }

    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator('ACROS');
    $pdf->SetAuthor('ACROS');
    $pdf->SetTitle('Lista de producto');
    $pdf->SetSubject('Lista de producto');
    $pdf->SetKeywords('ACROS, acros, mayorista, informática');
    $pdf->setPrintHeader(true);
    $pdf->setPrintFooter(false);
    $pdf->SetMargins(0, 0, 0);
    $pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
    $pdf->setLanguageArray($l); 
    $pdf->AddPage();

    $category = $_GET['c'];
    $getCategory = "SELECT * FROM prod_detalle WHERE fk_marca = '$category'";
    $getCategory = mysql_query($getCategory);
    $count = mysql_num_rows($getCategory);

    $txt = "result ".$count;
    // output the HTML content
    $pdf->writeHTML($txt, true, 0, true, 0);
    $pdf->SetY(-30);
    $pdf->SetX(0.65);
    $pdf->MultiCell(20, 0, $txtB, $border = 0,$align = 'L',$fill = 0,$ln = 1,$x = '',$y = '',$reseth = false, $stretch = 0, $ishtml = true, $autopadding = false, $maxh = 0);
    $pdf->Output('lista.pdf', 'I');
    ?>

and i'm getting this two warnings :

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /mnt/futurehome/netlogiq/public_html/acros/lista_pdf.php on line 64

Warning: Cannot modify header information - headers already sent by (output started at /mnt/futurehome/netlogiq/public_html/acros/lista_pdf.php:64) in /mnt/futurehome/netlogiq/public_html/acros/tcpdf/tcpdf.php on line 5405 TCPDF ERROR: Some data has already been output to browser, can't send PDF file

Can anyone help me with this ?? If run the query in phpmyadmin, it returns the wanted data. So the query works fine !

Was it helpful?

Solution

The reason you are getting the error from mysql_num_rows() is because you haven't initialized the connection to the database. You are also using the old (and deprecated as og PHP 5.5) MySQL interface - you should look into using mysqli or PDO instead.

A full explanation of how to initialize the connection to the database and communicate with it using the correct resource handle is, IMO, beyond the scope of an SO answer. Maybe start here instead:

http://www.php.net/manual/en/mysqli.quickstart.connections.php

The reason you're getting the second error is simply because the first error message is being sent to the browser before your call to $pdf->Output(). Once you get your database connection working and remove the error messages that problem will go away.

OTHER TIPS

Just remove the line

require_once('tcpdf/config/lang/eng.php');

and

edit the tcpdf.php file from the tcpdf folder: add the line ob_end_clean(); as below (3rd last line):

public function Output($name='doc.pdf', $dest='I') {
    //LOTS OF CODE HERE....}
    switch($dest) {
        case 'I': {
        // Send PDF to the standard output
        if (ob_get_contents()) {
        $this->Error('Some data has already been output, can\'t send PDF file');}
        //some code here....}
            case 'D': {         // download PDF as file
        if (ob_get_contents()) {
    $this->Error('Some data has already been output, can\'t send PDF file');}
            break;}
        case 'F':
        case 'FI':
        case 'FD': {
            // save PDF to a local file
                 //LOTS OF CODE HERE.....       break;}
        case 'E': {
            // return PDF as base64 mime email attachment)
        case 'S': {
            // returns PDF as a string
            return $this->getBuffer();
        }
        default: {
            $this->Error('Incorrect output destination: '.$dest);
        }
    }
           ob_end_clean(); //add this line here 
    return '';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top