0

I use fpdf to generate a pdf invoice. First I connect to the database and then I load the data. But the page I print is always empty!?

My connection code:

$con = mysql_connect("localhost","svenodj118_mrbs","diepenheim");

if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("svenodj_118_mrbs", $con);

$result = mysql_query('
    SELECT *
    FROM `mrbs_entry`
    WHERE start_time >= UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL 7 DAY)
        AND start_time < UNIX_TIMESTAMP(CURRENT_DATE + INTERVAL 1 DAY)
        AND create_by = "sven" 
    ORDER BY `start_time`, `room_id`
');

And my Generation code:

WHILE ($rows = mysql_fetch_array($result)) {
    $date = date("d/m/y", $rows['start_time']);   
    $time = date("H", $rows['end_time'])*60;
    $time += date("i", $rows['end_time']);
    $time2 = date("H", $rows['start_time'])*60;
    $time2 += date("i", $rows['start_time']);
    $time3 = ($time-$time2)/60;
    switch($rows['room_id'])
    {
        case 1:
            $room = "Grote Zaal";
            $prijs = $time3*10;
            break;
        case 2:
            $room = "Kleine Zaal";
            $prijs = $time3*5;
            break;
    }
    $totaalprijs += $prijs;
    var_dump($sql_result3);
    $pdf->ln();
    $pdf->SetXY(10,100);
    $pdf->cell(50,10,$room,0,0,'C',true);
    $pdf->SetXY(60, $hoogte+25);
    $pdf->cell(50,10,$date2,0,0,'C',true);
    $pdf->SetXY(100, $hoogte+25);
    $pdf->cell(50,10,$time3,0,0,'C',true);
    $pdf->SetXY(150, $hoogte+25);
    $pdf->cell(50,10,$prijs,0,0,'C',true);
    $hoogte+=25;
}
mysql_close();

Edit

The full code is:

<?php 
$con = mysql_connect("localhost","svenodj118_mrbs","diepenheim");


mysql_select_db("svenodj_118_mrbs", $con);

$result = mysql_query('SELECT *
FROM `mrbs_entry`
WHERE start_time >= UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL 7 DAY)
AND start_time < UNIX_TIMESTAMP(CURRENT_DATE + INTERVAL 1 DAY)
AND create_by = "sven" 
ORDER BY `start_time`, `room_id`');
$total=0;


//--------------------------
date_default_timezone_set('Europe/Amsterdam');
$date = date('m/d/Y h:i:s a', time());

require("fpdf17/fpdf.php"); 
$pdf=new FPDF(); 



$pdf->SetFont('Helvetica','',12);
$pdf->SetTextColor(1,1,1);
//var_dump(get_class_methods($pdf)); 
$pdf->AddPage(); 
$pdf->Image("./images/Dorpshoes5.png"); 
$pdf->SetXY(10, 35);
$pdf->Write(10,'Dorpshoes Gelster'); 
$pdf->SetXY(120, 35);
$pdf->Write(10,'Invoice'); 
$pdf->SetXY(10, 40);
$pdf->Write(10,'Gelselaarse weg 6'); 
$pdf->SetXY(120, 40);
$pdf->Write(10,'Gecreerd op: 5/11/2015'); 
$pdf->SetXY(10, 45);
$pdf->Write(10,'Gelselaar'); 

$pdf->SetXY(10, 55);
$pdf->Write(10,'Betaling:'); 
$pdf->SetXY(120, 55);
$pdf->Write(10,$rows2['organisatie']); 
$pdf->SetXY(10, 60);
$pdf->Write(10,'NL 12 RABO 0 123456789'); 
$pdf->SetXY(120, 60);
$pdf->Write(10,$rows2['facename']); 
$pdf->SetXY(10, 65);
$pdf->Write(10,'Betaling te voldoen binnen 14 dagen.'); 
$pdf->SetXY(120, 65);
$pdf->Write(10,$rows2['facemail']); 


$hoogte=75;
$pdf->ln();
$pdf->SetXY(10, 75);
$pdf->SetFillColor(238,238,238);
$pdf->cell(50,10,"Ruimte",0,0,'C',true);
$pdf->SetXY(60, 75);
$pdf->cell(50,10,"Datum",0,0,'C',true);
$pdf->SetXY(100, 75);
$pdf->cell(50,10,"Tijd",0,0,'C',true);
$pdf->SetXY(150, 75);
$pdf->cell(50,10,"Totaal Prijs",0,0,'C',true);

WHILE($rows1 = mysql_fetch_array($result)){

   $date = date("d/m/y", $rows1['start_time']);   
   $time = date("H", $rows1['end_time'])*60;
   $time += date("i", $rows1['end_time']);
   $time2 = date("H", $rows1['start_time'])*60;
   $time2 += date("i", $rows1['start_time']);
   $time3 = ($time-$time2)/60;
   switch($rows1['room_id'])
   {
   case 1:
   $room = "Grote Zaal";
   $prijs = $time3*10;
   break;
   case 2:
   $room = "Kleine Zaal";
   $prijs = $time3*5;
   break;
   }
   $date2='11';
   $totaalprijs += $prijs;
   $pdf->ln();
   $pdf->SetXY(10,100);
   $pdf->cell(50,10,$room,0,0,'C',true);
   $pdf->SetXY(60, $hoogte+25);
   $pdf->cell(50,10,$date2,0,0,'C',true);
   $pdf->SetXY(100, $hoogte+25);
   $pdf->cell(50,10,$time3,0,0,'C',true);
   $pdf->SetXY(150, $hoogte+25);
   $pdf->cell(50,10,$prijs,0,0,'C',true);
   $hoogte+=25;
   }



$pdf->Output(); 
?>

Thanks for the help:

Sven

Sven
  • 57
  • 6
  • Have you executed $pdf->Output()? Also enable error reporting to check if there is any PHP error. – santaka Dec 08 '15 at 12:46
  • 2
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Dec 08 '15 at 13:14
  • I edited with the full code now. I use the output. – Sven Dec 08 '15 at 14:23

0 Answers0