If you've been wanting to delve more deeply into HTML tables with PEAR, this article can help. It is excerpted from chapter 34 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).
In Chapters 29 and 32, you saw how to run queries and DML statements using the SQL Commands interface and PHP. Now it’s time to dig deeper into select queries and refine the results so you get exactly what you’re looking for, either in great detail or in summary.
In the first part of this chapter, we show you how to install and use the PEAR packageHTML_Tableto create basic HTML tables and populate them manually with constants as well as use a database table to populate an HTML table.
Next, we cover the basics of theSELECTstatement using subqueries to filter query results. This includes filtering rows with theWHEREclause, and sorting rows with theORDER BYclause. In addition, we show you how to use subqueries with other SQL statements such asUPDATE.
Finally, we take theHTML_Tableexamples from the first part of the chapter, the subquery techniques that follow, and custom PHP functions to create a generalized application to display any database table or query in a tabular format with sorting and paging functionality.
Using HTML_Table
Be it travel options, product summaries, or movie show times, displaying information in a tabular, or grid, format is one of the most commonplace presentational paradigms in use. And while from the very beginning Web developers have stretched the original intention of HTML tables to their boundaries, the introduction of XHTML and CSS is making Web-based tabular presentations more manageable than ever. In this section, you’ll learn how to build data-driven tables using PHP, Oracle Database XE, and the PEAR package HTML_Table.
While it’s certainly possible to output database data into an HTML table by hard-coding the table tag elements and attributes within your PHP code, doing so can quickly grow tedious and error-prone. Given the prevalence of table-driven output on even simple Web sites, the problems of mixing design and logic in this manner can quickly compound. So what’s the solution?HTML_Tableis already at your disposal through PEAR.
In addition to greatly reducing the amount of design-specific code you need to contend with, theHTML_Tablepackage also offers an easy way to incorporate CSS formatting attributes into the output. In this section, you’ll learn how to installHTML_Tableand use it to quickly build tabular data output. Note that the intent of this section is not to introduce you to everyHTML_Tablefeature, but rather to highlight some of the key characteristics that you’ll most likely want to use on a regular basis. See the PEAR Web site athttp://pear.php.net/package/HTML_Tablefor a complete breakdown ofHTML_Tablecapabilities.