11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 35 • PRACTICAL DATABASE QUERIESwww.it-ebooks.infoCREATE TABLE sales (id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,client_id INT UNSIGNED NOT NULL,order_time TIMESTAMP NOT NULL,sub_total DECIMAL(8,2) NOT NULL,shipping_cost DECIMAL(8,2) NOT NULL,total_cost DECIMAL(8,2) NOT NULL);Creating Tabular Output with PEARBe it travel options, product summaries, or movie show times, displaying information in a tabular, orgrid, format is one of the most commonplace presentational paradigms in use today—and webdevelopers have stretched the original intention of HTML tables to their boundaries. Happily, theintroduction of XHTML and CSS is making web-based tabular presentations more manageable thanever. In this section, you’ll learn how to build data-driven tables using <strong>PHP</strong>, <strong>MySQL</strong>, and a PEAR packagecalled HTML_Table.■ Note PEAR was introduced in Chapter 11. If you’re not yet familiar with PEAR, consider taking a moment toreview Chapter 11 before continuing.While it’s certainly possible to output database data into an HTML table by hard-coding the tabletag elements and attributes within your <strong>PHP</strong> 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 designand logic in this manner can quickly compound. So what’s the solution? Not surprisingly, one is alreadyat your disposal through PEAR, and it’s called HTML_Table.In addition to greatly reducing the amount of design-specific code you need to contend with, theHTML_Table package also offers an easy way to incorporate CSS formatting attributes into the output. Inthis section, you’ll learn how to install HTML_Table and use it to quickly build tabular data output. Notethat the intent of this section is not to introduce you to every HTML_Table feature, but rather to highlightsome of the key characteristics that you’ll most likely want to use on a regular basis. See the PEAR website for a complete breakdown of HTML_Table capabilities.Installing HTML_TableTo take advantage of HTML_Table‘s features, you need to install it from PEAR. Start PEAR, passing it thefollowing arguments:%>pear install -o HTML_TableBecause HTML_Table depends upon another package, HTML_Common, passing along the –o option alsoinstalls that package if it’s not presently available on the target system. Execute this command, andyou’ll see output similar to the following:674

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!