2013-06-21 43 views
0

我試圖創建的每個結果我從我的SQL查詢得到的條形碼。 基本上我有在HTML表格示出了結果,並且在最後一列我想這樣顯示的條形碼=到$行的值= [1]。我完全喪失瞭如何做到這一點。PHP查詢結果與條碼圖像

<?php 

//PHP Includes 
include('inc/database.php'); 
require_once('class/BCGFontFile.php'); 
require_once('class/BCGColor.php'); 
require_once('class/BCGDrawing.php'); 
require_once('class/Barcode39.php'); 

header('Content-Type: image/png'); 

// MSSQL Query 
$sql = "SELECT warehouse, pick_order_number, order_status, pick_order_type, customer_order_number 
     FROM pick_order_header 
     WHERE warehouse = 'XDGM' 
     AND order_status <> 'Complete' 
     AND order_status <> 'Closed' 
     AND pick_order_type <> 'Backorder'"; 
?> 

<!DOCTYPE HTML> 
<link rel="stylesheet" type="text/css" href="css/master.css"> 
<html> 
<title>Current Orders</title> 
<body> 

<table> 
<?php 
// SQLSRV Query 
$results = sqlsrv_query($conn, $sql); 
if($results === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 
    echo " 
      <table border=1> 
      <tr> 
       <th>Order Number</th> 
       <th>Order Status</th> 
       <th>Order Type</th> 
       <th>Customer Order</th> 
       <th>Barcode</th> 
      </tr>"; 
    while ($row = sqlsrv_fetch_array($results)) 
    { 
     $odrnum = $row[1]; 
     $odrstatus = $row[2]; 
     $odrtype = $row[3]; 
     $custorder = $row[4]; 
     $barcode = $row[1]; 

    echo " 
      <tr> 
       <td>$odrnum</td> 
       <td>$odrstatus</td> 
       <td>$odrtype</td> 
       <td>$custorder</td> 
       <td>$barcode</td> 
      </tr>"; 
    } 
    echo "</table>"; 

?> 
</table> 
</body> 
</html> 

要創建我知道我需要有

$code = new BCGcode39(); // Or another class name from the manual 
$code->setScale(2); // Resolution 
$code->setThickness(30); // Thickness 
$code->setForegroundColor($color_black); // Color of bars 
$code->setBackgroundColor($color_white); // Color of spaces 
$code->setFont($font); // Font (or 0) 
$code->parse('HELLO'); // Text 

$drawing = new BCGDrawing('', $colorfg); 
$drawing->setBarcode($code); 
$drawing->draw(); 
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG); 

在哪裏,我想看到條碼條碼是

<td>$barcode</td> 

我只是對如何實現它沒有線索。

回答

1

它似乎不那麼簡單,因爲你走近它。我從未使用過你展示的圖書館,我想你正在使用http://www.barcodephp.com/en/manual/BCGcode39

通過在該網站中所示的實施例中,我的數字從draw()方法的輸出是要生成對應於該圖像的字節流。有很多方法可以實現你想要的。其中一個將有一個進程(可能是其他文件),它將接收該字符串並輸出相應的條形碼,然後在您的html表格中調用它。

線沿線的東西:

1 - DrawBarcode.php

<?php 
require_once('class/BCGDrawing.php'); 
header('Content-Type: image/png'); 
$drawing = new BCGDrawing('', $colorfg); 
$drawing->setBarcode($_GET['code']); 
$drawing->draw(); 

2 - Table.php

<?php 
// MSSQL Query 
$sql = "SELECT warehouse, pick_order_number, order_status, pick_order_type, customer_order_number 
     FROM pick_order_header 
     WHERE warehouse = 'XDGM' 
     AND order_status <> 'Complete' 
     AND order_status <> 'Closed' 
     AND pick_order_type <> 'Backorder'"; 
?> 

<!DOCTYPE HTML> 
<link rel="stylesheet" type="text/css" href="css/master.css"> 
<html> 
<title>Current Orders</title> 
<body> 

<table> 
<?php 
// SQLSRV Query 
$results = sqlsrv_query($conn, $sql); 
if($results === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 
    echo " 
      <table border=1> 
      <tr> 
       <th>Order Number</th> 
       <th>Order Status</th> 
       <th>Order Type</th> 
       <th>Customer Order</th> 
       <th>Barcode</th> 
      </tr>"; 
    while ($row = sqlsrv_fetch_array($results)) 
    { 
     $odrnum = $row[1]; 
     $odrstatus = $row[2]; 
     $odrtype = $row[3]; 
     $custorder = $row[4];    

    echo " 
      <tr> 
       <td>$odrnum</td> 
       <td>$odrstatus</td> 
       <td>$odrtype</td> 
       <td>$custorder</td> 
       <td><img src="DrawBarcode.php?code=<?php echo $row[1];?>"/></td> 
      </tr>"; 
    } 
    echo "</table>"; 

?> 
</table> 
</body> 
</html> 

應該這樣做。另一種方式(非常相似)是將條形碼生成到服務器上的文件中,然後將它們作爲img標籤的來源引用。

+0

非常感謝您的回覆,我來看看使用這種方法超出內存允許,因爲是搶了許多畫。所以現在我感興趣的是將文件保存在服務器上,然後引用它們。您是否介意幫助我處理該場景 – eternityhq

+0

如果您閱讀http://www.barcodephp.com/en/userguide,您會看到BCGDrawing :: __構造的第一個參數恰恰是一個文件名,所以我想如果您使用該參數參數,draw方法應該將條碼留在該文件中,然後您可以簡單地使用該文件作爲img src。你應該注意到,如果這一切都改變了,你可能不會解決你的記憶問題。你應該研究一些重新使用BCGDrawing對象,並緩存圖像(爲了不產生兩次相同的圖像) – Muc

+0

謝謝你是非常有幫助的。 – eternityhq