Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to fetch data from database in php and display in pdf

require('fpdf/fpdf.php');

// Database Connection 
$conn = new mysqli('hostname', 'username', 'password', 'database');
//Check for connection error
if($conn->connect_error){
  die("Error in DB connection: ".$conn->connect_errno." : ".$conn->connect_error);    
}

$pdf = new FPDF();


<?php
require('fpdf/fpdf.php');
// Database Connection 
$conn = new mysqli('localhost', 'root', '', 'company');
//Check for connection error
if($conn->connect_error){
  die("Error in DB connection: ".$conn->connect_errno." : ".$conn->connect_error);    
}
// Select data from MySQL database
$select = "SELECT * FROM `empdata` ORDER BY id";
$result = $conn->query($select);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
while($row = $result->fetch_object()){
  $id = $row->id;
  $name = $row->name;
  $address = $row->address;
  $phone = $row->phone;
  $pdf->Cell(20,10,$id,1);
  $pdf->Cell(40,10,$name,1);
  $pdf->Cell(80,10,$address,1);
  $pdf->Cell(40,10,$phone,1);
  $pdf->Ln();
}
$pdf->Output();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php questions in tasks 
Php :: progressive variable php 
Php :: wc php get product variation stock 
Php :: php Sum of all the factors of a number 
Php :: Argument #1 ($baseObject) must be of type DateTimeInterface, string given 
Php :: Laravel: validate an integer field that needs to be greater than another 
Php :: php pdo memory exhausted 
Php :: how to make login and logout to blog with php without database or MySQL 
Php :: css dynamique avec php dans page http<style 
Php :: laravel import csv files 
Php :: Accept multiple space separated inputs 
Php :: laravel 8 app with more than one database 
Php :: como leer archivos .env php 
Php :: character encoding to remove question marks as apostrophe php code 
Php :: how to follow unfollow on buddypress ajax call 
Php :: disable laravel cors 
Php :: command line that convert html to php file 
Php :: laravel model where set fields laravel 
Php :: laravel eloquent where date today 
Php :: SMARTY compose variable key array 
Php :: how to search locations in php using ajax google script 
Php :: Target class [LoginController] does not exist. 
Php :: codeigniter apache remove index.php 
Php :: php if equal 
Php :: how to install mysql and phpmyadmin on windows 10 
Php :: remove exact characters from string using php 
Php :: recorrer un array php 
Php :: addphp calculate next letter 
Java :: import math java 
Java :: import android.support.v4.app.ActivityCompat; 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =