2016-01-20 40 views
0

我已经使用fpdf编码来创建pdf文档。该文档是数据库'测试'中人员的地址标签。目前有3行,但我的代码只能获取最近输入的1。基于sql数据的pdf地址标签只返回1

我该如何将它们全部取出?

<?php 
require('PDF_Label.php'); 
require('db_connect.php'); 

/*------------------------------------------------ 
To create the object, 2 possibilities: 
either pass a custom format via an array 
or use a built-in AVERY name 
------------------------------------------------*/ 

// Example of custom format 
// $pdf = new PDF_Label(array('paper-size'=>'A4', 'metric'=>'mm', 'marginLeft'=>1, 'marginTop'=>1, 'NX'=>2, 'NY'=>7, 'SpaceX'=>0, 'SpaceY'=>0, 'width'=>99, 'height'=>38, 'font-size'=>14)); 

// Standard format 
$result = $mysqli->query("SELECT * FROM test"); 


while ($row = $result->fetch_assoc()) { 
$driver = $row['driver']; 
$fline = $row['fline']; 
$sline = $row['sline']; 
$town = $row['town']; 
$town = $row['postcode']; 
$other = $row['other']; 

} 

$pdf = new PDF_Label('L7163'); 

$pdf->AddPage(); 


//ote 

// Print labels 

    $text = sprintf("%s\n%s\n%s\n%s %s %s", "$driver", "$fline", "$sline", "$town", "$postcode", "$other"); 
    $pdf->Add_Label($text); 



$pdf->Output(); 
?> 

回答

0

我假设你正在调用db_connect.php当建立一个数据库连接,但你没有引用您的函数调用连接:

$result = $mysqli->query($connection, "Select * from test");