Make multiple barcodes with simple script

Hi Expert,

I've found this exelent working PHP script that makes the barcodes. I've found it at this page.

<?
include "Barcode39.php"; 
$bc = new Barcode39("123-ABC"); 
$bc->barcode_text_size = 5; 
$bc->barcode_bar_thick = 4; 
$bc->barcode_bar_thin = 2; 
$bc->draw();
?>

Open in new window


Would there be a simple way to make this script write multiple barcodes with different values in one page?
LVL 1
SteynskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
The script above returns an image so to get multiple on one page you would need to have a script that returns an image based on parameterised input - something like this
<?php
include "Barcode39.php"; 
$label = isset($_GET['label']) ? $_GET['label'] : 'NO LABEL';
$size = isset($_GET['size']) ? $_GET['size'] : 5;
$thick = isset($_GET['thick']) ? $_GET['thick'] : 4;
$thin = isset($_GET['thin']) ? $_GET['thin'] : 2;

$bc = new Barcode39($label); 
$bc->barcode_text_size = $size; 
$bc->barcode_bar_thick = $thick; 
$bc->barcode_bar_thin = $thin; 
$bc->draw();

Open in new window

NB: Some hints for PHP script - don't use the short form of the script tag <? - rather use <?php
If your script contains only script then you can leave the closing tag off - this can prevent errors relating to blank characters after the closing tag.
You can now call multiple codes by passing parameters to the above script in an <img> tag like so
<img src="t1295.php?label=ABC-123" /><br/>
<img src="t1295.php?label=DEF-456" /><br/>
<img src="t1295.php?label=GHI-789" /><br/>
<img src="t1295.php?label=JKL-000" /><br/>

Open in new window

Working sample here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tncodeCommented:
Julian is correct and it should work in the same way as any streaming product with the IMG tag. For example:
http://support.idautomation.com/php-barcode/idautomation-code128.php?D=Testing123456
returns an image.
Chris StanyonWebDevCommented:
Just create a new Barcode39 each time you need to. Put the codes you want in an array and loop through them:

include "Barcode39.php";
$codes = array("Code 1", "Code 2", "Code 3");
		
foreach ($codes as $code):
    $bc = new Barcode39($code); 
    $bc->barcode_text_size = 5; 
    $bc->barcode_bar_thick = 4; 
    $bc->barcode_bar_thin = 2; 
    $bc->draw();
endforeach;

Open in new window

SteynskAuthor Commented:
Julian,

Thank you very much for the answer to my question and the advise.

Kind regards,

Steynsk
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.