24h購物| | PChome| 登入
2023-01-06 21:25:42| 人氣12| 回應0 | 上一篇 | 下一篇

若何利用PHP製作並匯出PDF報表

推薦 0 收藏 0 轉貼0 訂閱站台

 

好啦,將上面的檔案下載以後解緊縮放入網站的資料夾就能夠開始囉

則需要再下載chinese-unicode.rar

真的是一個超方便的東西喔 ^ ^~~

 

 

reportSQL.php

report.php

  1. <?php  session_start();
  2.  
  3. mysql_select_db($database, $test);
  4.  
  5. //index(首頁)
  6. $query_index = "SELECT * FROM `flow` WHERE date = CURDATE( ) AND page = 'index'";
  7. $index = mysql_query($query_index, $test) or die(mysql_error());
  8. $totalRows_index = mysql_num_rows($index);
  9. $query_index2 = "SELECT * FROM `flow` WHERE page = 'index'";
  10. $index2 = mysql_query($query_index2, $test) or die(mysql_error());
  11. $totalRows_index2 = mysql_num_rows($index2);
  12.  
  13. //introduce(品牌介紹)
  14. $query_introduce = "SELECT * FROM `flow` WHERE date = CURDATE( ) AND page = 'introduce'";
  15. $introduce = mysql_query($query_introduce, $test) or die(mysql_error());
  16. $totalRows_introduce = mysql_num_rows($introduce);
  17. $query_introduce2 = "SELECT * FROM `flow` WHERE page = 'introduce'";
  18. $introduce2 = mysql_query($query_introduce2, $test) or die(mysql_error());
  19. $totalRows_introduce2 = mysql_num_rows($introduce2);
  20.  
  21. //......................(其餘頁面寫法同上)
  22.  
  23. ?>
  24.  
複製代碼
  1. <?php
  2. require('chinese-unicode.php');            //匯入方才下載的中文化的FPDF
  3. require_once('../Connections/test.php');   //匯入貫穿連接資料庫的語法
  4. require_once('../require/reportSQL.php');  //匯入報表的SQL語法
  5. $pdf=new PDF_Unicode();                    //設立建設PDF_Unicode
  6. $pdf->Open();                              //開啟
  7. $pdf->AddPage();                           //新的一頁
  8. $pdf->AddUniCNShwFont('uni');              //加入中文
  9. $pdf->SetFont('uni','',16);                //設定字型與字體巨細
  10. //接著將資料放入一維陣列中
  11. $row0=array('瀏覽頁面','本日人數流量(人)','總人數流量(人)');
  12. $row1=array('首頁',$totalRows_index,$totalRows_index2);
  13. $row2=array('品牌介紹',$totalRows_introduce,$totalRows_introduce2);
  14. $row3=array('經營理念',$totalRows_manage,$totalRows_manage2);
  15. $row4=array('署理品牌',$totalRows_agent,$totalRows_agent2);
  16. $row5=array('產品',$totalRows_product,$totalRows_product2);
  17. $row6=array('公告發佈',$totalRows_publish,$totalRows_publish2);
  18. $row7=array('舉動新訊',$totalRows_activities,$totalRows_activities2);
  19. $row8=array('素材介紹',$totalRows_material,$totalRows_material2);
  20. $row9=array('營業據點',$totalRows_place,$totalRows_place2);
  21. $row10=array('聯絡我們',$totalRows_contact,$totalRows_contact2);
  22.  
  23. //今日人數流量統計
  24. $today=$totalRows_index+$totalRows_introduce+$totalRows_manage+$totalRows_agent+$totalRows_product+$totalRows_publish+$totalRows_activities+$totalRows_material+$totalRows_place+$totalRows_contact;
  25. $total=$totalRows_index2+$totalRows_introduce2+$totalRows_manage2+$totalRows_agent2+$totalRows_product2+$totalRows_publish2+$totalRows_activities2+$totalRows_material2+$totalRows_place2+$totalRows_contact2;
  26. $row11=array('統計',$today,$total);
  27. //再將資料放入2維陣列中
  28. $trow=array($row0,$row1,$row2,$row3,$row4,$row5,$row6,$row7,$row8,$row9,$row10,$row11);
  29.  
  30. //設定表格的寬度
  31. $w=array(60,65,60);
  32.  
  33. //迴圈
  34. for($j=0;$j<count($trow);$j++){
  35.   for($i=0;$i<count($trow[$j]);$i++){
  36.    $pdf->Cell($w[$i],7,$trow[$j][$i],1,0,'C');     //將資料放入表格內
  37.   } $pdf->Ln();                                    //下一列
  38. }
  39. $pdf->Output();                                   //輸出顯現
  40. ?>
  41.  
複製代碼
網站架設



 

  1. <?php
  2. $hostname = "localhost";   //主機名稱
  3. $database = "test";              //資料庫名稱
  4. $username = "xxxx";            //資料庫使用者帳號
  5. $password = "****";            //資料庫利用者暗碼
  6.  
  7. $test = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
  8. mysql_select_db("test",$test);
  9. mysql_query("set names 'utf8'");
  10.  
  11. ?>
  12.  
複製代碼

接下來從瀏覽器觀看的成效以下圖:

test.php


Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])

w
Cell width. If 0, the cell extends up to the right margin.
h
Cell height. Default value: 0.
txt
String to print. Default value: empty string.
border
Indicates if borders must be drawn around the cell. The value can be either a number:
0: no border網站架設
1: frame
or a string containing some or all of the following characters (in any order):
L: left
T: top
R: right
B: bottom
Default value: 0.
ln網站架設
Indicates where the current position should go after the call. Possible values are:
0: to the right
1: to the beginning of the next line
2: below
Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.
align
Allows to center or align the text. Possible values are:
L or empty string: left align (default value)
C: center
R: right align
fill
Indicates if the cell background must be painted (true) or transparent (false). Default value: false.
link
URL or identifier returned by AddLink().
Example

或直接點選這邊下載fpdf16.zip



 



 

起首可以到FPDF網站下載程式,固然FPDF的網站有講授也值得前去旁觀http://www.fpdf.org/

  1.  
  2. // Set font
  3. $pdf->SetFont('Arial','B',16);
  4. // Move to 8 cm to the right
  5. $pdf->Cell(80);
  6. // Centered text in a framed 20*10 mm cell and line break
  7. $pdf->Cell(20,10,'Title',1,1,'C');
複製代碼

1.png

因為FPDF的網站是英文的,是以若要利用中文字,



引用自:

台長: moorefjav4
人氣(12) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: NetYea |
此分類下一篇:php5與php7的區分是什麼
此分類上一篇:網站架設 若何用bootstrap製作RWD網站

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文