Reputation: 3
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:
$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:
$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. 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
Upvotes: 0
Views: 1178
Reputation: 11375
Tip: Don't include
whilst in the while
loop, move it above the loop.
Change your line to become;
$barcode = new Barcode39($row["reparationid"]);
$reparationid
doesn't exist in the script you've given, and if it does; it doesn't have the value you fetched from the database. (It does have the value of your database query string though)
Upvotes: 1