0

I am trying to follow the steps in an example on fpdfmakes webiste. However I am using sql server instead of mysql. Could someone give me some pointers so I can get this to work correctly? thanks

<?php

require('fpdf.php');

//Connect to your database
$serverName = "myserver";
$connectionOptions = array("Database"=>"mydb");
$conn = sqlsrv_connect( $serverName, $connectionOptions);
$tsql = "select name, lname from employees";  
//Select the Products you want to show in your PDF file

$Auditid = "";
$comments = "";

//For each row, add the field to the corresponding column
while($row = sqlsrv_fetch_array ($stmt )){
{
    $code = $row["Audtiid"];
    $name = substr($row["Comments"],0,20);

    $column_code = $column_code.$code."\n";
    $column_name = $column_name.$name."\n";

    //Sum all the Prices (TOTAL)

}
mssql_close($conn);

//Convert the Total Price to a number with (.) for thousands, and (,) for decimals.

//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,'Auditid',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'Comments',1,0,'L',1);
$pdf->SetX(135);

$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);

//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();
?>
2
Contributors
1
Reply
16
Views
10 Months
Discussion Span
Last Post by diafol
1

The DB engine shouldn't matter. Once the data is held in php variables, it's good to go. What part of the code is failing? Are you retrieving data from the DB at all? If so, the issue is with the fpdf (which I haven't checked yet). It's a good idea to break down the code into chunks to see where the failure is occurring.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.