![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
PHP: The Good Parts: Delivering the Best of PHP- P7
Số trang: 20
Loại file: pdf
Dung lượng: 435.17 KB
Lượt xem: 17
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
PHP: The Good Parts: Delivering the Best of PHP- P7: Vượt qua tất cả các hype về PHP và thâm nhập vào sức mạnh thực sự của ngôn ngữ này. Cuốn sách này khám phá những tính năng hữu ích nhất của PHP và làm thế nào họ có thể đẩy nhanh quá trình phát triển web, và giải thích lý do tại sao thường được sử dụng PHP yếu tố thường được sử dụng sai hoặc misapplied. Bạn sẽ tìm hiểu thêm phần nào sức mạnh để lập trình hướng đối tượng, và làm thế nào để sử dụng...
Nội dung trích xuất từ tài liệu:
PHP: The Good Parts: Delivering the Best of PHP- P7 $this->SetFont(,B); //Header // make an array for the column widths $w=array(85,40,15); // send the headers to the PDF document for($i=0;$iCell($w[$i],7,$header[$i],1,0,C,1); $this->Ln(); //Color and font restoration $this->SetFillColor(175); $this->SetTextColor(0); $this->SetFont(); //now spool out the data from the $data array $fill=true; // used to alternate row color backgrounds foreach($data as $row) { $this->Cell($w[0],6,$row[0],LR,0,L,$fill); // set colors to show a URL style link $this->SetTextColor(0,0,255); $this->SetFont(, U); $this->Cell($w[1],6,$row[1],LR,0,L,$fill, http://www.oreilly.com); // restore normal color settings $this->SetTextColor(0); $this->SetFont(); $this->Cell($w[2],6,$row[2],LR,0,C,$fill); $this->Ln(); // flips from true to false and vise versa $fill =! $fill; } $this->Cell(array_sum($w),0,,T); }}//connect to database$connection = mysql_connect(localhost,user, password);$db = library;mysql_select_db($db, $connection) or die( Could not open $db database);$sql = SELECT * FROM books ORDER BY pub_year;$result = mysql_query($sql, $connection) or die( Could not execute sql: $sql);// build the data array from the database records.While($row = mysql_fetch_array($result)) { $data[] = array($row[title], $row[ISBN], $row[pub_year] );}// start and build the PDF document$pdf = new PDF();//Column titles PDF Generation | 103 $header=array(Book Title,ISBN,Year); $pdf->SetFont(Arial,,14); $pdf->AddPage(); // call the table creation method $pdf->BuildTable($header,$data); $pdf->Output();In this code, we use the database connection and build two arrays to send to theBuildTable() custom method of this extended class. Inside the BuildTable() method,we set colors and font attributes for the table header, then send out the headers basedon the first array passed in. An array called $w (for width) sets the column widths andis used in the calls to the cell() methods.After the table header is sent out, we use the $data array that contains the databaseinformation and walk through that array with a foreach loop. Notice here that thecell() method uses LR for its border parameter. This refers to borders on the left andright of the cell in question, thus effectively adding the sides to the table rows. We alsoadd a URL link to the second column just to show that it can be done in connectionwith the table row construction. Finally, we use a $fill variable to flip back and forthso that the background color will alternate as the table is constructed row by row.The final call to the cell() method in this BuildTable() method draws the bottom ofthe table and closes off the columns.The result of executing this code in a browser is shown in Figure 8-11.Figure 8-11. Table data taken from MySQL placed in a dynamic PDF104 | Chapter 8: PHP and FriendsGraphical Reports GenerationJPGraph is used to make graphical statistical reports like bar charts and pie charts. Itis an object-oriented code library, so by now it should be fairly straightforward for youto use. As before, you access this library with a require statement.Typically, a graphical report will ask the user for input in order to build the report. Thisis information like the date range that the report will cover, the sorting order of thedata, and so on. In our samples, however, we will simply provide arrays with presetvalues to make them a little easier to review.Pie ChartsThe first sample graph that we will look at is a pie chart. In the following listing youwill see an array of data to be plotted on the chart assigned to a variable called $data;this is the data that would normally be provided by a data entry page, a select statementfrom a database, or a combination of both. We can do this after we bring in the ap-propriate libraries for the chart that we are about to build.JPGraph is a little different than other libraries in the sense that there is a basic libraryrequired by all graphs being generated, as well as individual specialized libraries, orsublibraries, that are more suited to each graph type. In this case, we use thejpgraph_pie.php file because we are creating a pie chart. After we reference the correctlibraries and provide the raw data, we instantiate the $piechart class from the PieGraph object and pass two numbers representing the width and height of the chart tothe constructor. Then we simply start us ...
Nội dung trích xuất từ tài liệu:
PHP: The Good Parts: Delivering the Best of PHP- P7 $this->SetFont(,B); //Header // make an array for the column widths $w=array(85,40,15); // send the headers to the PDF document for($i=0;$iCell($w[$i],7,$header[$i],1,0,C,1); $this->Ln(); //Color and font restoration $this->SetFillColor(175); $this->SetTextColor(0); $this->SetFont(); //now spool out the data from the $data array $fill=true; // used to alternate row color backgrounds foreach($data as $row) { $this->Cell($w[0],6,$row[0],LR,0,L,$fill); // set colors to show a URL style link $this->SetTextColor(0,0,255); $this->SetFont(, U); $this->Cell($w[1],6,$row[1],LR,0,L,$fill, http://www.oreilly.com); // restore normal color settings $this->SetTextColor(0); $this->SetFont(); $this->Cell($w[2],6,$row[2],LR,0,C,$fill); $this->Ln(); // flips from true to false and vise versa $fill =! $fill; } $this->Cell(array_sum($w),0,,T); }}//connect to database$connection = mysql_connect(localhost,user, password);$db = library;mysql_select_db($db, $connection) or die( Could not open $db database);$sql = SELECT * FROM books ORDER BY pub_year;$result = mysql_query($sql, $connection) or die( Could not execute sql: $sql);// build the data array from the database records.While($row = mysql_fetch_array($result)) { $data[] = array($row[title], $row[ISBN], $row[pub_year] );}// start and build the PDF document$pdf = new PDF();//Column titles PDF Generation | 103 $header=array(Book Title,ISBN,Year); $pdf->SetFont(Arial,,14); $pdf->AddPage(); // call the table creation method $pdf->BuildTable($header,$data); $pdf->Output();In this code, we use the database connection and build two arrays to send to theBuildTable() custom method of this extended class. Inside the BuildTable() method,we set colors and font attributes for the table header, then send out the headers basedon the first array passed in. An array called $w (for width) sets the column widths andis used in the calls to the cell() methods.After the table header is sent out, we use the $data array that contains the databaseinformation and walk through that array with a foreach loop. Notice here that thecell() method uses LR for its border parameter. This refers to borders on the left andright of the cell in question, thus effectively adding the sides to the table rows. We alsoadd a URL link to the second column just to show that it can be done in connectionwith the table row construction. Finally, we use a $fill variable to flip back and forthso that the background color will alternate as the table is constructed row by row.The final call to the cell() method in this BuildTable() method draws the bottom ofthe table and closes off the columns.The result of executing this code in a browser is shown in Figure 8-11.Figure 8-11. Table data taken from MySQL placed in a dynamic PDF104 | Chapter 8: PHP and FriendsGraphical Reports GenerationJPGraph is used to make graphical statistical reports like bar charts and pie charts. Itis an object-oriented code library, so by now it should be fairly straightforward for youto use. As before, you access this library with a require statement.Typically, a graphical report will ask the user for input in order to build the report. Thisis information like the date range that the report will cover, the sorting order of thedata, and so on. In our samples, however, we will simply provide arrays with presetvalues to make them a little easier to review.Pie ChartsThe first sample graph that we will look at is a pie chart. In the following listing youwill see an array of data to be plotted on the chart assigned to a variable called $data;this is the data that would normally be provided by a data entry page, a select statementfrom a database, or a combination of both. We can do this after we bring in the ap-propriate libraries for the chart that we are about to build.JPGraph is a little different than other libraries in the sense that there is a basic libraryrequired by all graphs being generated, as well as individual specialized libraries, orsublibraries, that are more suited to each graph type. In this case, we use thejpgraph_pie.php file because we are creating a pie chart. After we reference the correctlibraries and provide the raw data, we instantiate the $piechart class from the PieGraph object and pass two numbers representing the width and height of the chart tothe constructor. Then we simply start us ...
Tìm kiếm theo từ khóa liên quan:
phương pháp lập trình lập trình web với php ngôn ngữ lập trình php tính năng lập trình phpTài liệu liên quan:
-
Giáo trình Lập trình logic trong prolog: Phần 1
114 trang 206 0 0 -
Giáo trình Lập trình C căn bản
135 trang 176 0 0 -
Giáo trình Lập trình C căn bản: Phần 1
64 trang 170 0 0 -
66 trang 156 0 0
-
14 trang 137 0 0
-
Giáo trình lập trình hướng đối tượng - Lê Thị Mỹ Hạnh ĐH Đà Nẵng
165 trang 122 0 0 -
Bài giảng Phương pháp lập trình: Chương 9 - GV. Từ Thị Xuân Hiền
36 trang 115 0 0 -
47 trang 113 2 0
-
Giáo trình về môn Lập trình C căn bản
131 trang 50 0 0 -
Bài giảng Lập trình hướng đối tượng (dùng JAVA): Chương 1 - Trần Minh Thái
40 trang 42 0 0