0

我正在尝试为从 SQL 查询中获得的每个结果创建一个条形码。基本上我的结果显示在一个 HTML 表中,并且在最后一列中我想要显示一个条形码 = 到 $row = [1] 的值。我完全不知道如何做到这一点。

<?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>

我只是不知道如何实现它。

4

1 回答 1

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 - 表.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 标签的来源进行引用。

于 2013-06-21T16:35:21.193 回答