Guest User

Untitled

a guest
Nov 5th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <?php
  2.  
  3. Class dbObj{
  4. /* Database connection start */
  5. var $dbhost = "localhost";
  6. var $username = "root";
  7. var $password = "1";
  8. var $dbname = "1";
  9. var $conn;
  10. function getConnstring() {
  11. $con = mysqli_connect($this->dbhost, $this->username, $this->password, $this->dbname) or die("Connection failed: " . mysqli_connect_error());
  12.  
  13. /* check connection */
  14. if (mysqli_connect_errno()) {
  15. printf("Connect failed: %sn", mysqli_connect_error());
  16. exit();
  17. } else {
  18. $this->conn = $con;
  19. }
  20. return $this->conn;
  21. }
  22. }
  23.  
  24. <?php
  25. //include connection file
  26. include_once("/var/www/html/ecom1/ekart/connection.php");
  27. include_once('/var/www/html/ecom1/ekart/fpdf/fpdf.php');
  28.  
  29. class PDF extends FPDF
  30. {
  31. // Page header
  32. function Header()
  33. {
  34. // Logo
  35. $this->Image('logo.png',10,-1,70);
  36. $this->SetFont('Arial','B',13);
  37. // Move to the right
  38. $this->Cell(80);
  39. // Title
  40. $this->Cell(80,10,'Employee List',1,0,'C');
  41. // Line break
  42. $this->Ln(20);
  43. }
  44.  
  45. // Page footer
  46. function Footer()
  47. {
  48. // Position at 1.5 cm from bottom
  49. $this->SetY(-15);
  50. // Arial italic 8
  51. $this->SetFont('Arial','I',8);
  52. // Page number
  53. $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  54. }
  55. }
  56.  
  57. $db = new dbObj();
  58. $connString = $db->getConnstring();
  59. $display_heading = array('id'=>'ID', 'order_id'=> 'Name', 'payment_type'=> 'payment');
  60.  
  61. $result = mysqli_query($connString, "SELECT id, order_id, payment_type FROM orders") or die("database error:". mysqli_error($connString));
  62. $header = mysqli_query($connString, "SHOW columns FROM orders");
  63.  
  64. $pdf = new PDF();
  65. //header
  66. $pdf->AddPage();
  67. //foter page
  68. $pdf->AliasNbPages();
  69. $pdf->SetFont('Arial','B',12);
  70. foreach($header as $heading) {
  71. $pdf->Cell(40,12,$display_heading[$heading['Field']],1);
  72. }
  73. foreach($result as $row) {
  74. $pdf->Ln();
  75. foreach($row as $column)
  76. $pdf->Cell(40,12,$column,1);
  77. }
  78. $pdf->Output();
  79. ?>
Add Comment
Please, Sign In to add comment