简体   繁体   English

PHP条码-在单个页面中显示多个条码

[英]php barcode - display multiple barcode in single page

I created a php page that print the barcode. 我创建了一个可打印条形码的php页面。 Just to view it before i print it on an A4. 只是要查看它,然后再在A4上打印它。 Still in testing phase. 仍处于测试阶段。 The codes are as below. 代码如下。

<?php
include('include/conn.php');
include('include/Barcode39.php'); 
$sql="select * from barcode where b_status = 'NOT-PRINTED'";
$result=mysqli_query($conn,$sql);
echo mysqli_num_rows($result);

$i=0;

while($row=mysqli_fetch_assoc($result)){
$acc_no = $row["b_acc_no_code"];
$bc = new Barcode39($row["b_acc_no_code"]);
echo $bc->draw();
$bc->draw($acc_no.$i.".jpg");
echo '<br /><br />';
$i++;
}
?>

Without the while loop, it can be printed, but only one barcode. 如果没有while循环,则只能打印一个条形码。 How to make it generate, for example in the database have 5 values, it will print 5 barcode in the same page. 如何使其生成,例如在数据库中有5个值,它将在同一页面上打印5个条形码。 Thanks in advance 提前致谢

Try to use another bar code source. 尝试使用其他条形码源。 Because It is generate only one bar code per page. 因为它每页仅生成一个条形码。 Can't able to create multiple bar code per page. 每页无法创建多个条形码。

I know this is an older post but comes up in searches so is probably worth replying to. 我知道这是一篇较旧的文章,但出现在搜索中,因此可能值得回复。

I have successfully used the Barcode39 to display multiple barcodes. 我已成功使用Barcode39来显示多个条形码。 The trick is to get base64 data from the class and then display the barcodes in separate HTML tags. 技巧是从类中获取base64数据,然后在单独的HTML标签中显示条形码。

The quickest way to do this is to add a $base64 parameter to the draw() method: 最快的方法是在draw()方法中添加一个$ base64参数:

   public function draw($filename = null, $base64 = false) {

Then, near the end of the draw() method, modify to buffer the imagegif() call and return the output in base64: 然后,在draw()方法的结尾附近,进行修改以缓冲imagegif()调用,并在base64中返回输出:

// check if writing image
if ($filename) {
    imagegif($img, $filename);
} 
// NEW: Return base 64 for the barcode image
else if ($base64) {
    ob_start();
    imagegif($img);
    $image_data = ob_get_clean();

    imagedestroy($img);
    return base64_encode($image_data);
} 
// display image
else {
    header("Content-type: image/gif");
    imagegif($img);
}

Finally, to display multiples from the calling procedure, construct the image HTML in the loop and display: 最后,要显示调用过程的倍数,请在循环中构造图像HTML并显示:

// assuming everything else has been set up, end with this...
$base64 = $barcode->draw('', true);     // Note the second param is set for base64
$html = '';
for ($i = 0; $i < $numBarcodes; $i++) {
    $html .= '<img src="data:image/gif;base64,'.$base64.'">';
}
die('<html><body>' . $html . '</body></html>');

I hope this helps anyone else facing this challenge. 我希望这对其他面临挑战的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM