开发者

problem with variable scope

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

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Falco System');
$pdf->SetTitle('Llogaria');
$pdf->SetSubject('Llogaria');

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE , PDF_HEADER_STRING);

// set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setPrintHeader(false);
$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_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_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', '', 10);

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

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
//$image = $pdf->Image("tcpdf/images/logo.png", 15, 10, 60, 15, 'PNG', '', '', true, 150, '', false, false, 1, false, false, false);
global $db;
$result = $db->query("SELECT * FROM orders ORDER BY date DESC limit 1");
$row = mysql_fetch_array($result);
$emri = $row['name'];
$html = <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<style>

    h1 {
        color: navy;
        font-family: times;
        font-size: 24pt;
        text-decoration: underline;
    }
    p.first {
        color: #003300;
        font-family: helvetica;
        font-size: 12pt;
    }
    p.first span {
        color: #006600;
        font-style: italic;
    }
    p#second {
        color:#000;
        font-family: helvetica;
        font-size: 8pt;
        text-align: justify;
    }
    p#falemenderim {
        color:#000;
        font-family: times;
        font-size: 12pt;
        text-align: justify;
    }

    p#second > span {
        background-color: #FFFFAA;
    }
    table.first {
        color: #003300;
        font-family: helvetica;
        font-size: 8pt;
        background-color: #FFFFFF;
    }
    td {
    border: 1px solid #BFBFBF;  
    background-color: #FFFFFF;
    }
    div.test {
        color: #CC0000;
        background-color: #FFFF66;
        font-family: helvetica;
        font-size: 10pt;
        border-style: solid solid solid solid;
        border-width: 2px 2px 2px 2px;
        border-color: green #FF00FF blue red;
        text-align: center;
    }
    td.Addressa {
        border:1px solid #FFFFFF;
        text-align:right;
    }
    td.logo {
        border:1px solid #FFFFFF;
    }
    .bolder {
        font-weight:bold;
    }
    .hide {
    border-left:3px solid #FFFFFF;
    border-bottom:3px solid #FFFFFF;
    }
    .kuq {
    background-color: red;
    color:#FFFFFF;
    }
</style>

<br/><br/>
<table class="thise" cellpadding="0" cellspacing="0">
<tr>
    <td height="50" class="logo">$image</td>
    <td class="Addressa">
        Falco system<br/>
        123 Rruga<br/>
        Tetove, MKD<br/>
        000 - 000 000<br/>
        email@firma.com
    </td>
</tr>
</table>


<br />

<table class="first" cellpadding="4" cellspacing="0">
<tr class="bolder">
    <td class="kuq">Pasagjeri</td>
    <td class="kuq">Prej</td>
    <td class="kuq">Deri</td>
</tr>
<tr>
    <td>$emri Islami</td>
    <td>Tetove</td>
    <td>Berlin</td>
</tr>
</table>
<table cellpadding="4" cellspacing="0" >

<tr>
    <td class="hide" width="345"></td>
    <td class="bolder" width="80">&Ccedil;mimi</td>
    <td >$ 100.00</td>
</tr>
</table>

<p id开发者_StackOverflow社区="falemenderim">
    Ju falemenderojme qe keni zgjedhur te udhetoni me agjensionin tone, ju deshirojme nje rruge te mbare!
</p>

<p id="second">
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porta nisl at dui semper ut semper lectus volutpat. 
Integer sollicitudin cursus mi et fermentum. Pellentesque in sem id felis commodo auctor. Nulla fringilla dui ac odio
 iaculis vel posuere eros dignissim. Donec nulla odio, pretium vitae consectetur sit amet, hendrerit interdum mauris.<br/> 
- Proin tincidunt consectetur nisi vel pellentesque. Ut ac felis quis lorem porttitor convallis at in diam. Sed molestie, 
 sem at molestie posuere, nibh justo auctor nunc, eu posuere sem purus eget ipsum. In auctor gravida vulputate. Aenean in<br/> 
- sapien purus, non ornare tortor. Cras nec risus lacus. Integer dictum sodales bibendum. 
</p>
EOF;

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();

//Close and output PDF document
$pdf->Output('tiketa.pdf', 'I');
require_once ('classes/class.db.php');
$db = new MySQL(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME, false);

?>

This gives me this error:

Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\falco\GeneratePDF.php on line 64

I have tried to make the $db variable global, when I initiate and require the db class which connects to the DB in the top of the script then I get another error! I dont know what to do to make this work!

Thank you for your time and help.


It looks like your $db declaration is all the way at the bottom. Put it at the top instead and get rid of the global $db since I don't see this as a function call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜