Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. include('FPDF-master/font');
  3. require('FPDF-master/fpdf.php');
  4.  
  5. //Connect to your database
  6. $servername = "localhost";
  7. $username = "root";
  8. $password = "";
  9. $dbname = "test";
  10.  
  11. // Create con
  12.  
  13. $conn = new mysqli($servername, $username, $password, $dbname);
  14. // Check connection
  15. if ($conn->connect_error) {
  16. die("Connection failed: " . $conn->connect_error);
  17. }
  18.  
  19.  
  20. //Create new pdf file
  21. $pdf=new FPDF();
  22.  
  23. //Disable automatic page break
  24. $pdf->SetAutoPageBreak(false);
  25.  
  26. //Add first page
  27. $pdf->AddPage();
  28.  
  29. //set initial y axis position per page
  30. $y_axis_initial = 25;
  31.  
  32. //print column titles
  33. $pdf->SetFillColor(232,232,232);
  34. $pdf->SetFont('Arial','B',12);
  35. $pdf->SetY($y_axis_initial);
  36. $pdf->SetX(25);
  37.  
  38. $pdf->Cell(30,6,'name',1,0,'L',1);
  39. $pdf->Cell(100,6,'amount',1,0,'L',1);
  40. $pdf->Cell(30,6,'trans_id',1,0,'R',1);
  41. $pdf->Cell(30,6,'time_paid',1,0,'R',1);
  42.  
  43. $y_axis = $y_axis + $row_height;
  44.  
  45. //Select the Products you want to show in your PDF file
  46. $result=mysql_query('SELECT name, amount, trans_id, msisdn, time_paid FROM customer',$link);
  47.  
  48. //initialize counter
  49. $i = 0;
  50.  
  51. //Set maximum rows per page
  52. $max = 25;
  53.  
  54. //Set Row Height
  55. $row_height = 6;
  56.  
  57. while($row = mysql_fetch_array($result))
  58. {
  59. //If the current row is the last one, create new page and print column title
  60. if ($i == $max)
  61. {
  62. $pdf->AddPage();
  63.  
  64. //print column titles for the current page
  65. $pdf->SetY($y_axis_initial);
  66. $pdf->SetX(25);
  67. $pdf->Cell(30,6,'name',1,0,'L',1);
  68. $pdf->Cell(100,6,'amount',1,0,'L',1);
  69. $pdf->Cell(30,6,'trans_id',1,0,'R',1);
  70. $pdf->Cell(30,6,'time_paid',1,0,'R',1)
  71.  
  72. //Go to next row
  73. $y_axis = $y_axis + $row_height;
  74.  
  75. //Set $i variable to 0 (first row)
  76. $i = 0;
  77. }
  78.  
  79. $name = $row['name'];
  80. $amount = $row['amount'];
  81. $trans_id = $row['trans_id'];
  82. $time_paid = $row['time_paid'];
  83.  
  84. $pdf->SetY($y_axis);
  85. $pdf->SetX(25);
  86. $pdf->Cell(30,6,$name,1,0,'L',1);
  87. $pdf->Cell(100,6,$amount,1,0,'L',1);
  88. $pdf->Cell(30,6,$trans_id,1,0,'R',1);
  89. $pdf->Cell(30,6,$time_paid,1,0,'R',1);
  90.  
  91. //Go to next row
  92. $y_axis = $y_axis + $row_height;
  93. $i = $i + 1;
  94. }
  95.  
  96. mysql_close($link);
  97.  
  98. //Send file
  99. $pdf->Output();
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement