Solved

Need to print the result of a MySQL query (via PHP page) to a label printer.

Posted on 2008-10-15
6
1,087 Views
Last Modified: 2013-12-13
Need to print the result of a MySQL query (via PHP page) to a label printer.

The query results have been formatted to return and display on the screen in the proper size and layout for the 1" tall x 2" labels.

I will include the php function that formats the results of the query.

I know there are several PDF options available but to be honest it really seems like hours of work for something that really by today's standards should be pretty simple...so it seems anyway.

What I want to happen ideally, is for the result set to be converted to pdf and emailed where it will be automatically printed.

I've got roughly 70,000 lines of code all working perfectly except for these freaking tiny labels!!!

Many thanks in advance.

Rapturer

function show(){
                
        if($this->queryresult === NULL)
                $this->get();
 
        $count = 1;
        while($therecord = $this->db->fetchArray($this->queryresult)){
                for ($i = 1; $i <= $therecord["quantity"]; $i++) {
                        ?>
                        <!-- /////////        <tr id="li<?//php echo $count?>" > /////////-->
                        <tr>
                                <td class="label_workorder"><b><?php echo "SG".$therecord["invoiceid"] ?></b></td>
                                <td class="label_quantity"> <?php echo $i." OF ".$therecord["quantity"]?></td>
                        </tr>
                        
                        <tr>
                        <td class"label_barcode" colspan="2">
                           <?php
 
        $bc = new c39Barcode('bcx', "SG".$therecord["invoiceid"]);
   //	    $bc->setFactor(1);
        echo $bc->getBarcode();
        //$bc->exec($this); // prefered method
 ?>
                        </td>
                        </tr>
                        <tr>
                                <td class="label_sizes"><?php echo $therecord["width"]?>" X  <?php echo $therecord["height"]?>"</td>
                                <td class="label_partnumber"><?php echo "<span class='lowercase'>". "p/n"."</span>"." "." - ".$therecord["partnumber"] ?></td>
                        </tr>
                        <tr>
                         <td class="label_spacer" colspan="2"></td>
                        </tr>         
                        <?php
                } // endfor
 
        $count++;
 
        }//endwhile
}//end method

Open in new window

0
Comment
Question by:Rapturer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22722640
Is the printer directly available to PHP? On the same machine or over the LAN?

Or are you generating a web page and having the user print the labels?
0
 
LVL 1

Author Comment

by:Rapturer
ID: 22722687
I actually have either option available to me. The thermal label printer is in fact available to the machine generating the output.

I am actually just trying to find any way to accomplish this printing...I can adjust from that point.

Thanks!

Rapturer
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22722945
What sort of printer? I have a Delphi app which prints under the control of PHP. PHP does all the gathering and creates a file for the Delphi app to print. Printing under PHP is either PDF (I would use fpdf as it is very simple) or plain text.

The reason I used our external app is that it allowed me to build custom layouts using a proper designer.

How are you currently sending data to the printer?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22723006
As for printing, you have to understand the difference between a line printer and a page printer.

A line printer prints plain text (normally). It may support bold, underline, etc. The old dot matrix printers were like this.

You would use escape sequences to alter the font settings, etc.

Page printers use a page description language (commonly PostScript) to describe the way the page is to be printed. The Postscript engine in the printer then interprets this and converts it to a piece of paper.

I would strongly recommend using PDF output as this does all the hard work for you.

Once you've got the PDF file, you can script Acrobat to print it without too much difficulty.
0
 
LVL 1

Author Comment

by:Rapturer
ID: 22723382
Ok, so it seems like pdf is the best way...The printer in question is a Zebra Thermal label printer "ZP 2824"

Is there an online resource that you can recommend for fpdf label scripts?

Thanks - Rapturer
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 22723431
PDF construction is the same no matter what printer - that's the point.

Take a look at http://fpdf.org

Lots of goodies there, including examples.

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question