We help IT Professionals succeed at work.

PHP Mailing Labels by Range

fcruz5
fcruz5 asked
on
289 Views
Last Modified: 2013-12-13
Hi,

The following code will display a form where I can type in the id's seperated by comma to print out the mailing labels that I want.

I want to add these two fields so I can specify a range of id's to print mailing labels for:

Choose a Range: <input type="text" name="range1" /> <input type="text" name="range2 />

For example, this is what the 2 new fields would do:

In the first field I can put id# "200" and the next field I may put "300". So, when I click "Generate Labels" it will print out all of the id's from the 200 - 300 range.

How can I do something like this?

Below is the code that I have now:

<?php

if(!empty($_POST['labels']))
{
 
        define('FPDF_FONTPATH','font/');
    require_once('PDF_Label.php');  
        require('conn.php');
    $labels = explode(',', $_POST['labels']);

    $pdf = new PDF_Label('L7163', 'mm', 1, 2);
    $pdf->Open();
    $pdf->AddPage();

    foreach($labels as $labelId)
    {
        $query = "SELECT work.id, work.title, work.name, work.address, work.city, work.state, work.zip, region.id
            FROM work   work, region   region
            WHERE work.id = region.id AND work.id = " . $labelId;
        $result = mysql_query($query);
        $row = mysql_fetch_assoc($result);
       
        //for($i=1;$i<=40;$i++)
        $pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s, %s, %s", $row['title'], $row['name'], $row['address'], $row['city'], $row['state'], $row['zip'] ));

    }
    $pdf->Output();
               
}
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
List ids separated by a comma: <input type="text" name="labels" /><br />
<input type="submit" value="Generate Labels" />

<!--new fields go here-->

</form>
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.