Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-01-2009, 02:54 PM   PM User | #1
dlow128
New to the CF scene

 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dlow128 is an unknown quantity at this point
can someone pls help with barcode php script?

I am currently working on a barcode php script, in the example shown below the script will generate
a barcode based on a ramdom mysql query. The problem i have is I need to be able to display the same image multiple
times based on a variable. To elaborate, mysql will run a query and fetch a row which will contain a unque code to be used as
the barcode and a number to indicate how many barcodes need to be displayed on page. Is there a way i can use this number as
a variable to be able to display the same barcode multiple times in a column one underneath the other. Thanking you in advance

script:

(Edit: see later post)

Last edited by Inigoesdr; 08-01-2009 at 07:07 PM..
dlow128 is offline   Reply With Quote
Old 08-01-2009, 06:33 PM   PM User | #2
Sergey Popov
New Coder

 
Join Date: Jul 2009
Location: Internet
Posts: 37
Thanks: 0
Thanked 4 Times in 4 Posts
Sergey Popov is an unknown quantity at this point
How to position dynamicly created images php

Quote:
Is there a way i can use this number as
a variable to be able to display the same barcode multiple times in a column one underneath the other.
By "this number" do you mean the one that is set to 1 in your query example (... limit 1) ? If so, and if you need to query and display say 10 bar codes, just add a loop for each record in your recordset like this:

PHP Code:
$r=mysql_query("select codes from list order by rand() limit 10");
for(
$j=0;$j<mysql_num_rows($r);$j++){
  
$query mysql_fetch_row($r);

  
$text strtoupper($query[0]);
  
  
// .... all your code goes here ...
  // just need to set $barcodeheight = 40 * mysql_num_rows($r) before loop
  // also add variable $ypos and increment it by 40 each iteration


Sergey Popov is offline   Reply With Quote
Old 08-01-2009, 06:55 PM   PM User | #3
dlow128
New to the CF scene

 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dlow128 is an unknown quantity at this point
How to position dynamicly created images php

This script uses mysql to generate a barcode and duplicates the image 10 times one underneath the other to produce what looks like a continious barcode. My problem is i need to separate the 10 images down the page to allow for a text area. Any ideas?
I appreciate any input, many thanks

Code:
<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$query = mysql_fetch_row(mysql_query("select codes from list order by rand() limit 1"));

    $barcodeheight=40;
    $barcodethinwidth=2;
    $barcodethickwidth=$barcodethinwidth*3;
    $codingmap  =  Array( "0"=> "000110100", "1"=> "100100001",
        "2"=> "001100001", "3"=> "101100000", "4"=> "000110001",
        "5"=> "100110000", "6"=> "001110000", "7"=> "000100101",
        "8"=> "100100100", "9"=> "001100100", "A"=> "100001001",
        "B"=> "001001001", "C"=> "101001000", "D"=> "000011001",
        "E"=> "100011000", "F"=> "001011000", "G"=> "000001101",
        "H"=> "100001100", "I"=> "001001100", "J"=> "000011100",
        "K"=> "100000011", "L"=> "001000011", "M"=> "101000010",
        "N"=> "000010011", "O"=> "100010010", "P"=> "001010010",   
        "Q"=> "000000111", "R"=> "100000110", "S"=> "001000110",
        "T"=> "000010110", "U"=> "110000001", "V"=> "011000001",
        "W"=> "111000000", "X"=> "010010001", "Y"=> "110010000",
        "Z"=> "011010000", " "=> "011000100", "$"=> "010101000",
        "%"=> "000101010", "*"=> "010010100", "+"=> "010001010",
        "-"=> "010000101", "."=> "110000100", "/"=> "010100010");
    $text  =  strtoupper($query[0]);
    $textlen  =  strlen($text);
    $barcodewidth  =  ($textlen)*(7*$barcodethinwidth + 3*$barcodethickwidth)-$barcodethinwidth;
    $im  =  ImageCreate($barcodewidth,$barcodeheight);
    $black  =  ImageColorAllocate($im,0,0,0);
    $white  =  ImageColorAllocate($im,255,255,255);
    imagefill($im,0,0,$white);
    $xpos=0;
    for  ($idx=0;$idx<$textlen;$idx++)  {
        $char  =  substr($text,$idx,1);
        // make  unknown  chars  a  '-';
        if  (!isset($codingmap[$char]))  $char  =  "-";
        for  ($baridx=0;$baridx<=8;$baridx++)  {
            $elementwidth  =  (substr($codingmap[$char],$baridx,1))  ? $barcodethickwidth : $barcodethinwidth;
            if  (($baridx+1)%2)  imagefilledrectangle($im,$xpos,0,$xpos + $elementwidth-1,$barcodeheight,$black);
            $xpos+=$elementwidth;
        }
        $xpos+=$elementwidth;
    }
// Duplication
  $barcodesRequired = 10;
$im2 = imageCreate($barcodewidth,$barcodeheight*$barcodesRequired);
for($x = 0; $x< $barcodesRequired; $x ++){
    imagecopy($im2,$im,0,$barcodeheight*$x,0,0,$barcodewidth,$barcodeheight);
}

Header( "Content-type:  image/gif");
ImageGif($im2);
ImageDestroy($im);
ImageDestroy($im2);
?>
dlow128 is offline   Reply With Quote
Old 08-01-2009, 07:07 PM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
dlow128, please don't create duplicate posts for the same issue.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Tags
barcode, img src, php, variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:18 AM.


Advertisement
Log in to turn off these ads.