Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class dbObj{
- /* Database connection start */
- var $dbhost = "localhost";
- var $username = "root";
- var $password = "1";
- var $dbname = "1";
- var $conn;
- function getConnstring() {
- $con = mysqli_connect($this->dbhost, $this->username, $this->password, $this->dbname) or die("Connection failed: " . mysqli_connect_error());
- /* check connection */
- if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- } else {
- $this->conn = $con;
- }
- return $this->conn;
- }
- }
- <?php
- //include connection file
- include_once("/var/www/html/ecom1/ekart/connection.php");
- include_once('/var/www/html/ecom1/ekart/fpdf/fpdf.php');
- class PDF extends FPDF
- {
- // Page header
- function Header()
- {
- // Logo
- $this->Image('logo.png',10,-1,70);
- $this->SetFont('Arial','B',13);
- // Move to the right
- $this->Cell(80);
- // Title
- $this->Cell(80,10,'Employee List',1,0,'C');
- // Line break
- $this->Ln(20);
- }
- // Page footer
- function Footer()
- {
- // Position at 1.5 cm from bottom
- $this->SetY(-15);
- // Arial italic 8
- $this->SetFont('Arial','I',8);
- // Page number
- $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
- }
- }
- $db = new dbObj();
- $connString = $db->getConnstring();
- $display_heading = array('id'=>'ID', 'order_id'=> 'Name', 'payment_type'=> 'payment');
- $result = mysqli_query($connString, "SELECT id, order_id, payment_type FROM orders") or die("database error:". mysqli_error($connString));
- $header = mysqli_query($connString, "SHOW columns FROM orders");
- $pdf = new PDF();
- //header
- $pdf->AddPage();
- //foter page
- $pdf->AliasNbPages();
- $pdf->SetFont('Arial','B',12);
- foreach($header as $heading) {
- $pdf->Cell(40,12,$display_heading[$heading['Field']],1);
- }
- foreach($result as $row) {
- $pdf->Ln();
- foreach($row as $column)
- $pdf->Cell(40,12,$column,1);
- }
- $pdf->Output();
- ?>
Add Comment
Please, Sign In to add comment