Jump to content

fpdf


searls03

Recommended Posts

I need a little help with fpdf:

<?php
include_once("connect.php");

if($_POST['submit']){
$startdate=$_POST['startdate'];
$enddate=$_POST['enddate'];




$sql = mysql_query("SELECT * FROM transactions where date between '$startdate' and '$enddate' ");
while($row = mysql_fetch_array($sql)){{
$date = $row["date"];
$product = $row["product"];
$month = $row["month"];
$day = $row["day"];
$year = $row["year"];
$category = $row["category"];
$academy = $row["academy"];
$price = $row["price"];
$priceunit = $row["priceunit"];
$quantity = $row["quantity"];
}
// Query member data from the database and ready it for display


require('fpdf.php');
class PDF extends FPDF

{






function EAN13($x=1, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode(13,5,$barcode,$h,$w,13);
}

function UPC_A($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,12);
}

function GetCheckDigit($barcode)
{
    //Compute the check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    $r=$sum%10;
    if($r>0)
        $r=10-$r;
    return $r;
}

function TestCheckDigit($barcode)
{
    //Test validity of check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    return ($sum+$barcode[12])%10==0;
}

function Barcode($x, $y, $barcode, $h, $w, $len)
{
    //Padding
    $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
    if($len==12)
        $barcode='0'.$barcode;
    //Add or control the check digit
    if(strlen($barcode)==12)
        $barcode.=$this->GetCheckDigit($barcode);
    elseif(!$this->TestCheckDigit($barcode))
        $this->Error('Incorrect check digit');
    //Convert digits to bars
    $codes=array(
        'A'=>array(
            '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
            '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
        'B'=>array(
            '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
            '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
        'C'=>array(
            '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
            '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
        );
    $parities=array(
        '0'=>array('A','A','A','A','A','A'),
        '1'=>array('A','A','B','A','B','B'),
        '2'=>array('A','A','B','B','A','B'),
        '3'=>array('A','A','B','B','B','A'),
        '4'=>array('A','B','A','A','B','B'),
        '5'=>array('A','B','B','A','A','B'),
        '6'=>array('A','B','B','B','A','A'),
        '7'=>array('A','B','A','B','A','B'),
        '8'=>array('A','B','A','B','B','A'),
        '9'=>array('A','B','B','A','B','A')
        );
    $code='101';
    $p=$parities[$barcode[0]];
    for($i=1;$i<=6;$i++)
        $code.=$codes[$p[$i-1]][$barcode[$i]];
    $code.='01010';
    for($i=7;$i<=12;$i++)
        $code.=$codes['C'][$barcode[$i]];
    $code.='101';
    //Draw bars
    for($i=0;$i<strlen($code);$i++)
    {
        if($code[$i]=='1')
            $this->Rect($x+$i*$w,$y,$w,$h,'F');
    }
    //Print text uder barcode
    $this->SetFont('Arial','B',12);
    $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len));
}


//Instanciation of inherited class

function Header()
{

global $name;
	global $date;
	global $product;
	global $month;
	global $day;
	global $year;
	global $academy;
	global $price;
	global $priceunit;
	global $category;
	global $quantity;

	 // get the variable $name1 into the scope of this function
    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(70);
    //Title
    $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C);
// Query member data from the database and ready it for display




    //Line break
    $this->Ln(20);
$this->Cell(0,0,'',1,0);
$this->Ln(20);
$this->cell(50,10, 'Product:', 1,0);
$this->cell(50,10, 'Category:', 1,0);
$this->cell(50,10, 'Price:', 1,0);
$this->Ln(10);
$this->cell(50,10,$product, 'L,R',0);

$this->cell(50,10, $category, 'L',0);
	$this->cell(50,10, $price, 'L,R',0);



}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','B',;
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Output('ticket.pdf', 'I');}?>

 

Problem I am having is running the code through a loop.  I need the products and such to run through the loop of querying the database so that all the entries in database meet the specs.  please help:)

Link to comment
https://forums.phpfreaks.com/topic/256959-fpdf/
Share on other sites

Ok.  What I am trying to do is run the code that makes the cells serveral times......so that in my database all the rows that meet the date specs will display.  currently it is only displaying one row instead of all the rows.  Here is the updated code:

if($_POST['submit']){
$startdate=$_POST['startdate'];
$enddate=$_POST['enddate'];




$sql = mysql_query("SELECT * FROM transactions where date between '$startdate' and '$enddate' ");
while($row = mysql_fetch_array($sql)){
$date = $row["date"];
$product = $row["product"];
$month = $row["month"];
$day = $row["day"];
$year = $row["year"];
$category = $row["category"];
$academy = $row["academy"];
$price = $row["price"];
$priceunit = $row["priceunit"];
$quantity = $row["quantity"];
}
// Query member data from the database and ready it for display


require('fpdf.php');
class PDF extends FPDF

{






function EAN13($x=1, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode(13,5,$barcode,$h,$w,13);
}

function UPC_A($x, $y, $barcode, $h=16, $w=.35)
{
    $this->Barcode($x,$y,$barcode,$h,$w,12);
}

function GetCheckDigit($barcode)
{
    //Compute the check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    $r=$sum%10;
    if($r>0)
        $r=10-$r;
    return $r;
}

function TestCheckDigit($barcode)
{
    //Test validity of check digit
    $sum=0;
    for($i=1;$i<=11;$i+=2)
        $sum+=3*$barcode[$i];
    for($i=0;$i<=10;$i+=2)
        $sum+=$barcode[$i];
    return ($sum+$barcode[12])%10==0;
}

function Barcode($x, $y, $barcode, $h, $w, $len)
{
    //Padding
    $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
    if($len==12)
        $barcode='0'.$barcode;
    //Add or control the check digit
    if(strlen($barcode)==12)
        $barcode.=$this->GetCheckDigit($barcode);
    elseif(!$this->TestCheckDigit($barcode))
        $this->Error('Incorrect check digit');
    //Convert digits to bars
    $codes=array(
        'A'=>array(
            '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
            '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
        'B'=>array(
            '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
            '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
        'C'=>array(
            '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
            '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
        );
    $parities=array(
        '0'=>array('A','A','A','A','A','A'),
        '1'=>array('A','A','B','A','B','B'),
        '2'=>array('A','A','B','B','A','B'),
        '3'=>array('A','A','B','B','B','A'),
        '4'=>array('A','B','A','A','B','B'),
        '5'=>array('A','B','B','A','A','B'),
        '6'=>array('A','B','B','B','A','A'),
        '7'=>array('A','B','A','B','A','B'),
        '8'=>array('A','B','A','B','B','A'),
        '9'=>array('A','B','B','A','B','A')
        );
    $code='101';
    $p=$parities[$barcode[0]];
    for($i=1;$i<=6;$i++)
        $code.=$codes[$p[$i-1]][$barcode[$i]];
    $code.='01010';
    for($i=7;$i<=12;$i++)
        $code.=$codes['C'][$barcode[$i]];
    $code.='101';
    //Draw bars
    for($i=0;$i<strlen($code);$i++)
    {
        if($code[$i]=='1')
            $this->Rect($x+$i*$w,$y,$w,$h,'F');
    }
    //Print text uder barcode
    $this->SetFont('Arial','B',12);
    $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len));
}


//Instanciation of inherited class

function Header()
{

global $name;
	global $date;
	global $product;
	global $month;
	global $day;
	global $year;
	global $academy;
	global $price;
	global $priceunit;
	global $category;
	global $quantity;

	 // get the variable $name1 into the scope of this function
    //Logo
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(70);
    //Title
    $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C);
// Query member data from the database and ready it for display




    //Line break
    $this->Ln(20);
$this->Cell(0,0,'',1,0);
$this->Ln(20);
$this->cell(50,10, 'Product:', 1,0);
$this->cell(50,10, 'Category:', 1,0);
$this->cell(50,10, 'Price:', 1,0);
$this->Ln(10);
$this->cell(50,10,$product, 'L,R',0);

$this->cell(50,10, $category, 'L',0);
	$this->cell(50,10, $price, 'L,R',0);



}

//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','B',;
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Output('ticket.pdf', 'I');}

 

does this make more sense?

Link to comment
https://forums.phpfreaks.com/topic/256959-fpdf/#findComment-1317308
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.