0

我的第一个 php 问题...

我正在使用 fpdf 生成 pdf 文件。我正在做的网站的原始版本在打印输出上使用了通用图像。我想将其更改为基于 id 的图像。

我的问题是在检索 ID 的查询运行之前声明了带有图像的标题。这可能很容易解决,但不是零 php-exp...

这是我的代码:

<?php
require('fpdf.php');
import_request_variables("GP", "rvar_");

$prn_con = mysql_connect('localhost', 'root', '');
mysql_select_db('db');

class PDF extends FPDF{
    function Header(){
        $this->Image('../../images/logo_generic.gif',170,8,30);
        }
    }

$pdf=new PDF();
$pdf->Open();
$tok = strtok($rvar_bestellkeys,",");

while ($tok){
    $result = mysql_query('SELECT * FROM bk WHERE bestellkey = "'.$tok.'"');
    $i = 0; 
    $fCount = mysql_num_fields($result);
    while($row=mysql_fetch_row($result)){
        while ($i < $fCount){
            $fName = mysql_field_name($result, $i); 
            $$fName = trim($row[$i]);
            $i++; 
            $strcont = strlen ($$fName);
            }
            $i=0; 
    }

查询结果之一是我要包含在 header() 徽标路径中的 ID。

问题
如何从我的内部设置 header() 路径while-loop?循环打印出文档(单页/多页),每个页面的右上角都应该有徽标。

感谢帮助!

编辑:
这是整个 php 脚本:

<?php
require('fpdf.php');
import_request_variables("GP", "rvar_");

$prn_con = mysql_connect('localhost', 'root', '');
mysql_select_db('db');

$resultsprache = mysql_query("SELECT * FROM sprachen WHERE sprache = '".$rvar_sprache."'");
while($row=mysql_fetch_row($resultsprache)){
    $fName = trim($row[2]);
    $$fName = trim($row[3]);
    }

$FileN = $tx_bestellung. '_'.date("YmdHis").'.pdf';
$title = $tx_bestellung;

class PDF extends FPDF{
    function Header(){
        $this->Image('../../images/logo_klein.gif',170,8,30);
        }
    }

 $pdf=new PDF();
 $pdf->Open();
 $pdf->AliasNbPages();
 $pdf->AddPage();
 $pdf->SetTitle($title);
 $pdf->SetFont('Arial','',8);

 $tok = strtok($rvar_bestellkeys,",");

 while ($tok){
    $result = mysql_query('SELECT * FROM bK WHERE bestellkey = "'.$tok.'"');
    $i = 0; 
    $fCount = mysql_num_fields($result);
    while($row=mysql_fetch_row($result)){
        while ($i < $fCount){
            $fName = mysql_field_name($result, $i); 
            $$fName = trim($row[$i]);
            $i++; 
            $strcont = strlen ($$fName);
            }
        $i=0; 
    }
$pdf->Cell(190,7,$tx_bestellung. " " .$tx_nr. " " .$bestellkey,0,1,'L');
    $pdf->Ln(8);
$pdf->Cell(190,5,$tx_verkaeufer,0,1);
$pdf->Cell(30,4,'ILN/GLN:',0,0);
$pdf->Cell(65,4,$vk_iln,0,1);
$pdf->Cell(30,4,$tx_firma. ':',0,0);
$pdf->Cell(65,4,$vk_firma,0,0);
$pdf->Cell(30,4,$tx_bestellnummer. ':',0,0);
$pdf->Cell(65,4,$bestellkey,0,1);
$pdf->Cell(30,4,$tx_adresse. ':',0,0);
$pdf->Cell(65,4,$vk_adresse,0,0);
$pdf->Cell(30,4,$bestelldatum. ':',0,0);
    $bestelldatum = (substr($bestelldatum, 8,2)).'.'.(substr($bestelldatum, 5, -3)).'.'.(substr($bestelldatum, 0, -6));
$pdf->Cell(65,4,$bestelldatum,0,1);
$pdf->Cell(30,4,$tx_plz. ', ' .$tx_ort. ':',0,0);
$pdf->Cell(65,4,$vk_plz.' '.$vk_ort,0,0);
.... 
$i=0; 
$result = mysql_query('SELECT * FROM bP WHERE bestellkey = "'.$tok.'"');
$fCount = mysql_num_fields($result);
$pdf->Cell(9,8,$tx_pos,1,0,'C');
$pdf->Cell(23,8,"EAN/GTIN",1,0,'C');
$pdf->Cell(43,8,$tx_bezeichnung,1,0,'C');
$pdf->Cell(10,8,$tx_groesse,1,0,'C');
$pdf->Cell(10,8,$tx_farbe,1,0,'C');
$pdf->Cell(15,8,$tx_preis,1,0,'C');
$pdf->Cell(12,8,$tx_einheit,1,0,'C');
$pdf->Cell(15,8,$tx_menge,1,0,'C');
$pdf->Cell(15,8,$tx_menge. "\n" .$tx_bestaetigt,1,0,'C');
$pdf->Cell(18,8,$tx_summe,1,1,'C');
...

$tok = strtok(",");
if($tok != ""){
    $pdf->AddPage();
}
}

mysql_close($prn_con);
$pdf->Output($FileN, 'D');

?>
4

1 回答 1

1

快速且很脏,但应该可以:

    <?php
    require('fpdf.php');
    import_request_variables("GP", "rvar_");

    $prn_con = mysql_connect('localhost', 'root', '');
    mysql_select_db('db');

    $resultsprache = mysql_query("SELECT * FROM sprachen WHERE sprache = '".$rvar_sprache."'");
    while($row=mysql_fetch_row($resultsprache)){
        $fName = trim($row[2]);
        $$fName = trim($row[3]);
        }

    $FileN = $tx_bestellung. '_'.date("YmdHis").'.pdf';
    $title = $tx_bestellung;

    $tok = strtok($rvar_bestellkeys,",");

    while ($tok){
        $result = mysql_query('SELECT * FROM bK WHERE bestellkey = "'.$tok.'"');
        $i = 0; 
        $fCount = mysql_num_fields($result);
        while($row=mysql_fetch_row($result)){

            if ($something === true) {
                $my_magic_id = $row['my_magic_id_column'];
            }

            if (isset($my_magic_id) && !class_exists('PDF')) {
                class PDF extends FPDF{
                    function Header(){
                        global $my_magic_id;
                        $this->Image('../../images/logo_klein.gif',170,8,30);
                        }
                    }

                $pdf=new PDF();
                $pdf->Open();
                $pdf->AliasNbPages();
                $pdf->AddPage();
                $pdf->SetTitle($title);
                $pdf->SetFont('Arial','',8);

            }

            while ($i < $fCount){
                $fName = mysql_field_name($result, $i); 
                $$fName = trim($row[$i]);
                $i++; 
                $strcont = strlen ($$fName);
                }
            $i=0; 
        }
    $pdf->Cell(190,7,$tx_bestellung. " " .$tx_nr. " " .$bestellkey,0,1,'L');
        $pdf->Ln(8);
    $pdf->Cell(190,5,$tx_verkaeufer,0,1);
    $pdf->Cell(30,4,'ILN/GLN:',0,0);
    $pdf->Cell(65,4,$vk_iln,0,1);
    $pdf->Cell(30,4,$tx_firma. ':',0,0);
    $pdf->Cell(65,4,$vk_firma,0,0);
    $pdf->Cell(30,4,$tx_bestellnummer. ':',0,0);
    $pdf->Cell(65,4,$bestellkey,0,1);
    $pdf->Cell(30,4,$tx_adresse. ':',0,0);
    $pdf->Cell(65,4,$vk_adresse,0,0);
    $pdf->Cell(30,4,$bestelldatum. ':',0,0);
        $bestelldatum = (substr($bestelldatum, 8,2)).'.'.(substr($bestelldatum, 5, -3)).'.'.(substr($bestelldatum, 0, -6));
    $pdf->Cell(65,4,$bestelldatum,0,1);
    $pdf->Cell(30,4,$tx_plz. ', ' .$tx_ort. ':',0,0);
    $pdf->Cell(65,4,$vk_plz.' '.$vk_ort,0,0);
    .... 
    $i=0; 
    $result = mysql_query('SELECT * FROM bP WHERE bestellkey = "'.$tok.'"');
    $fCount = mysql_num_fields($result);
    $pdf->Cell(9,8,$tx_pos,1,0,'C');
    $pdf->Cell(23,8,"EAN/GTIN",1,0,'C');
    $pdf->Cell(43,8,$tx_bezeichnung,1,0,'C');
    $pdf->Cell(10,8,$tx_groesse,1,0,'C');
    $pdf->Cell(10,8,$tx_farbe,1,0,'C');
    $pdf->Cell(15,8,$tx_preis,1,0,'C');
    $pdf->Cell(12,8,$tx_einheit,1,0,'C');
    $pdf->Cell(15,8,$tx_menge,1,0,'C');
    $pdf->Cell(15,8,$tx_menge. "\n" .$tx_bestaetigt,1,0,'C');
    $pdf->Cell(18,8,$tx_summe,1,1,'C');
    ...

    $tok = strtok(",");
    if($tok != ""){
        $pdf->AddPage();
    }
    }

    mysql_close($prn_con);
    $pdf->Output($FileN, 'D');

    ?>
于 2012-07-30T11:24:22.720 回答