2017-04-06 5 views
0

Ich habe diesen Beispielcode von meinem Dozenten. Ich möchte den Code ändern, damit er meine Daten aus der Datenbank abrufen kann, um einen Barcode zu generieren. Ich habe ein paar Artikel gelesen, aber ich habe immer noch eine Idee, Barcode zu generieren. Was soll ich jetzt tun? Ihre Hilfe wird sehr geschätzt.So generieren Sie Barcode in PHP

<?php 
 
// Including all required classes 
 
require_once('class/BCGFontFile.php'); 
 
require_once('class/BCGColor.php'); 
 
require_once('class/BCGDrawing.php'); 
 

 
// Including the barcode technology 
 
require_once('class/BCGcode39.barcode.php'); 
 

 
// Loading Font 
 
$font = new BCGFontFile('./font/Arial.ttf', 18); 
 

 
// Don't forget to sanitize user inputs 
 
$text = isset($_GET['text']) ? $_GET['text'] : '7895565'; 
 

 
// The arguments are R, G, B for color. 
 
$color_black = new BCGColor(0, 0, 0); 
 
$color_white = new BCGColor(255, 255, 255); 
 

 
$drawException = null; 
 
try { 
 
    $code = new BCGcode39(); 
 
    $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($text); // Text 
 
} catch(Exception $exception) { 
 
    $drawException = $exception; 
 
} 
 

 
/* Here is the list of the arguments 
 
1 - Filename (empty : display on screen) 
 
2 - Background color */ 
 
$drawing = new BCGDrawing('', $color_white); 
 
if($drawException) { 
 
    $drawing->drawException($drawException); 
 
} else { 
 
    $drawing->setBarcode($code); 
 
    $drawing->draw(); 
 
} 
 

 
// Header that says it is an image (remove it if you save the barcode to a file) 
 
header('Content-Type: image/png'); 
 
header('Content-Disposition: inline; filename="barcode.png"'); 
 

 
// Draw (or save) the image into PNG format. 
 
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG); 
 
?>

+0

Also nicht Sie wissen Wie benutzt man 'mysqli' oder' PDO'? – Justinas

+0

@Justinas Ich weiß, wie man mysqli verwendet, aber mein Problem ist, ich weiß nicht, welchen Teil im Quellcode ich oben ändern sollte. – user9791

Antwort

0

Ihr Barcode aus diesem Code generiert wird: $code->parse($text); // Text

Wo $text ist $text = isset($_GET['text']) ? $_GET['text'] : '7895565';

Also alles, was Sie tun müssen, um $text = $db->fetch();

+0

Ich weiß nicht, wie man in dieser Form schreibt '$ db-> fetch();', haben Sie einfachere Art und Weise? – user9791

+0

@ user9791 Es ist PDO-Implementierung Beispiel, ersetzen Sie es mit tatsächlichen Code von PDO. Sie wissen also, wie man PDO benutzt oder nicht? Denn wenn nicht - wird die Frage als zu weit geschlossen. – Justinas

+0

Ist es so? '$ db \t = mysqli_connect (" localhost "," root "," "," smposf "); \t \t $ als \t \t = mysqli_query ($ db, "* aus Barcode auswählen"); // wo sdate = ' "$ sdate.."' \t \t while ($ b = mysqli_fetch_array ($ as)) \t \t { \t \t \t $ Barcode = $ b [ 'Barcode']; \t \t \t echo "$ barcode", "
", "
"; \t} – user9791

Verwandte Themen