简体   繁体   English

从ID数据库打印条形码

[英]Print Barcode from ID database

After my last barcode question i'm back with another. 在我最后一个条形码问题之后,我又回来了。 This barcode script: http://www.shayanderson.com/php/php-barcode-generator-class-code-39.htm works fine with a static number, or static variable: 此条形码脚本: http : //www.shayanderson.com/php/php-barcode-generator-class-code-39.htm可以使用静态数字或静态变量正常工作:

$reparationid = uniqid();

// include Barcode39 class 
include "Barcode39.php"; 

// set Barcode39 object 
$barcode = new Barcode39("$reparationid"); 

// display new barcode 
$barcode->draw();

Bu, i want the $reparationID out of the database, the last added entry.i tried this, and it works without barcode: Bu,我想将$ reparationID从数据库中删除,最后添加的入口。我尝试过此操作,并且它可以在没有条形码的情况下工作:

$reparationid = "SELECT reparationid FROM reparation ORDER BY added DESC LIMIT 1";
$result = $link->query($reparationid);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        print($row ["reparationid"]);
    }
}
else {
    echo "0 results";
}

as asked, the reparationid is shown as number, so it works. 根据要求,reparationid显示为数字,因此可以使用。 Now i wanted to merge those 2 scripts, but that is the point where it goes wrong. 现在,我想合并这两个脚本,但这就是出错的地方。 It doesn't work at all. 它根本不起作用。 I tried this: 我尝试了这个:

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        print($row ["reparatieid"]);

        // include Barcode39 class 
include "Barcode39.php"; 

       // set Barcode39 object 
$barcode = new Barcode39("$reparationid"); 

       // display new barcode 
$barcode->draw();

    }
}
else {
    echo "0 results";
}

There is a blue question mark, nothing more.. Any ideas? 有一个蓝色的问号,仅此而已。

Thanks, 谢谢,

Br, Daan Br,大安

Tip: Don't include whilst in the while loop, move it above the loop. 提示:不要include ,而在while循环,将其移动上述循环。

Change your line to become; 改变你的路线成为;

$barcode = new Barcode39($row["reparationid"]);

$reparationid doesn't exist in the script you've given, and if it does; $reparationid在您提供的脚本中不存在,如果存在,则不存在; it doesn't have the value you fetched from the database. 它没有您从数据库中获取的值。 (It does have the value of your database query string though) (尽管它确实具有数据库查询字符串的值)

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

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