views:

91

answers:

1

Using an addon of FPDF, I am printing labels using PHP/MySQL (http://www.fpdf.de/downloads/addons/29/). I'd like to be able to have the user select how many labels to print. For example, if the query puts out 10 records and the user wants to print 3 labels for each record, it prints them all in one set. 1,1,1,2,2,2,3,3,3...etc. Any ideas?

     <?php
            require_once('auth.php'); 
            require_once('../config.php'); 
            require_once('../connect.php');     

            require('pdf/PDF_Label.php');

            $sql="SELECT $tbl_members.lastname, $tbl_members.firstname, 
    $tbl_members.username, $tbl_items.username, $tbl_items.itemname 
FROM $tbl_members, $tbl_items
WHERE $tbl_members.username = $tbl_items.username";
            $result=mysql_query($sql);

            if(mysql_num_rows($result) == 0){
            echo "Your search criteria does not return any results, please try again.";
            exit();
            }

            $pdf = new PDF_Label("5160");

            $pdf->AddPage();

            // Print labels
            while($rows=mysql_fetch_array($result)){
                $name = $rows['lastname'].', '.$rows['firstname';
                $item= $rows['itemname'];

                $text = sprintf("  * %s *\n  %s\n", $name, $item);
                $pdf->Add_Label($text);
            }

            $pdf->Output('labels.pdf', 'D');
            ?>
+1  A: 

Assuming that a variable like $copies is an integer of how many copies they want made, I would make the following modification:

// Print labels
while( $row = mysql_fetch_array( $result ) ){
  // Run Once for Each Result
    $name = $row['lastname'].', '.$row['firstname'];
    $item = $row['itemname'];
    $text = sprintf("  * %s *\n  %s\n", $name, $item);
    if( isset( $copies ) ) {
      // The Copies Variable exists
        for( $i=0 ; $i<$copies ; $i++ ) {
          // Run X times - Once for each Copy
            $pdf->Add_Label($text);
        }
    } else {
      // The Copies Variable does not exist - Assume 1 Copy
        $pdf->Add_Label($text);
    }
}

This should provide the required functionality.

Lucanos
Perfect! THANKS!
Michael