SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Eugene Oregon
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb PHP Script to Print Labels

    Does anyone have an Idea how to get names and addresses from MySql database and format them so they can print on to label stock on a local printer from our websites membership database? I understand that there are mahy types of label stock out there however, even if we could print to one type of labels would be great.

  2. #2
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm,

    one option is to make a html file called mylable.html and use a file like this to process it...

    Code:
    <?php
    $db = mysql_connect($host,$user,$pass);
    mysql_select($table);
    $query = "SELECT * FROM database WHERE item_name='$item_label_to_make'";
    $query_string = mysql_query($query);
    $element=mysql_fetch_array($query_string);
    
    */then, use this loop. On your .html page you need to add 
    tags that match the fieldname in your database, ie ([name]) 
    Place these in your html file where you want the data to appear. 
    This works as a template.
    */
    $fp = fopen("mylable.html", "r");
    $lable = fread($fp, filesize(mylable.html"));
    
    foreach($element as $key=>$value) {
         $lable = str_replace("[$key]",$value,$lable);
    }
    
    //then print it. I dont know so i guess....
    
    print($lable);
    
    ?>
    The mylable.html file can be a table with some lables, like [stock], [product_name]. Thses labels need to be EXACTLY as in the database. You dont have to put all the fields on. If str_replace dosent find the text it wont error. So use [field]. This means its easy to change the lable shape and sixe without PHP knowledge. Other wise you may want to make a full php script. But as you asked i guess you dont knwo how too!!

    Just open the page as makelable.php?item_label_to_make=item_name
    Hope that helps


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •