2016-01-20 21 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");