Search
 
SCRIPT & CODE EXAMPLE
 

PHP

fpdf tutorial php mysql

<?php
//SHOW A DATABASE ON A PDF FILE
//CREATED BY: Carlos Vasquez S.
//E-MAIL: cvasquez@cvs.cl
//CVS TECNOLOGIA E INNOVACION
//SANTIAGO, CHILE

require('fpdf.php');

//Connect to your database
include("conectmysql.php");

//Select the Products you want to show in your PDF file
$result=mysql_query("select Code,Name,Price from Products ORDER BY Code",$link);
$number_of_products = mysql_numrows($result);

//Initialize the 3 columns and the total
$column_code = "";
$column_name = "";
$column_price = "";
$total = 0;

//For each row, add the field to the corresponding column
while($row = mysql_fetch_array($result))
{
    $code = $row["Code"];
    $name = substr($row["Name"],0,20);
    $real_price = $row["Price"];
    $price_to_show = number_format($row["Price"],',','.','.');

    $column_code = $column_code.$code."
";
    $column_name = $column_name.$name."
";
    $column_price = $column_price.$price_to_show."
";

    //Sum all the Prices (TOTAL)
    $total = $total+$real_price;
}
mysql_close();

//Convert the Total Price to a number with (.) for thousands, and (,) for decimals.
$total = number_format($total,',','.','.');

//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();

//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;

//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(20,6,'CODE',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'NAME',1,0,'L',1);
$pdf->SetX(135);
$pdf->Cell(30,6,'PRICE',1,0,'R',1);
$pdf->Ln();

//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
$pdf->MultiCell(20,6,$column_code,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(100,6,$column_name,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$columna_price,1,'R');
$pdf->SetX(135);
$pdf->MultiCell(30,6,'$ '.$total,1,'R');

//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
    $pdf->SetX(45);
    $pdf->MultiCell(120,6,'',1);
    $i = $i +1;
}

$pdf->Output();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: redirect www to non-www wordpress multisite 
Php :: wp query compare like and or 
Php :: how to get session variables from cookie string 
Php :: install php 7.4 amazon linux 2 
Php :: laravel create registration bootstrap 
Php :: how to fetch data from two tables in mysqli using php 
Php :: WP Hero Img 
Php :: phpmyadmin timedeconnexion : a placer tt en bas dans "config.inc.php" 
Php :: YYYYMMDDTHHMMSSZ php 
Php :: Attempt to read property "headers" on string 
Php :: How to calculate age using query builder in laravel? 
Php :: phpdoc array of strings 
Php :: how to cut middle part of text php 
Php :: count letters in string without space or characters and numbers in php 
Php :: how can we send attached file with notification in gmail in laravel 8 
Php :: cache.backend.null 
Php :: polymorph laravel return order by 
Php :: /usr/local/bin/php /home/tbmholdingltd/public_html/tugent/php artisan schedule:run /dev/null 2&1 
Php :: Warning: Undefined array key "index_no" in C:xampphtdocs ruestudent eports.php on line 54 Fatal error: Uncaught TypeError: mysqli_fetch_array(): 
Php :: get.krnl.key 
Php :: 0.01 bnb to php 
Php :: how to depreciate a class in php comments 
Php :: How to remove repetitive values from foreach loop in php laravel 
Php :: sql update views +1 
Php :: php echo comand 
Php :: php datetime format 
Php :: !array_push($stack, "apple", "raspberry"); 
Php :: Dein Benutzer-Profil um weitere Social Media Accounts erweitern 
Php :: php linkify text 
Php :: search highlighting 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =