• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

PHP Mailing Labels by Range

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>
0
fcruz5
Asked:
fcruz5
1 Solution
 
gamebitsCommented:
Try this if I may suggest, not exactly what you are looking for though this script will start the result at the input and will run for so many as entered into the second field so istead of having a range from (to use your example) 200 to 300 you would have to put 200 in the first field and 100 in the second field (start at 200 and grab the next 100).

<?php

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

    $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
            LIMIT $start, $howmany;
        $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 />
Start at: <input type="text" name="start" size="5" />
How Many: <input type="text name="howmany" size="5" />

<input type="submit" value="Generate Labels" />

</form>
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now