您好我的PHP代码:
<?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');
?>
我得到了这两个警告:
警告:mysql_num_rows()要求参数1为resource,boolean 在/mnt/futurehome/netlogiq/public_html/acros/lista_pdf.php中给出 第64行
警告:无法修改标头信息 - 已发送的标头 (输出始于 /mnt/futurehome/netlogiq/public_html/acros/lista_pdf.php:64)in /mnt/futurehome/netlogiq/public_html/acros/tcpdf/tcpdf.php在线 5405 TCPDF错误:某些数据已经输出到浏览器,无法解决 发送PDF文件
任何人都可以帮我吗?如果在phpmyadmin中运行查询,则返回所需数据。所以查询工作正常!
答案 0 :(得分:0)
您从mysql_num_rows()
收到错误的原因是您尚未初始化与数据库的连接。您还使用旧的(并且不推荐使用og PHP 5.5)MySQL接口 - 您应该考虑使用mysqli或PDO。
如何初始化与数据库的连接并使用正确的资源句柄与之通信的完整说明是IMO,超出了SO答案的范围。也许从这里开始:
http://www.php.net/manual/en/mysqli.quickstart.connections.php
您收到第二个错误的原因仅仅是因为在您致电$pdf->Output()
之前,第一条错误消息正在发送到浏览器。一旦数据库连接正常工作并删除了问题就会消失的错误消息。
答案 1 :(得分:0)
只需删除
行即可require_once('tcpdf/config/lang/eng.php');
和
从tcpdf文件夹编辑tcpdf.php文件: 添加 ob_end_clean(); 行,如下所示(第3行最后一行):
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 '';
}