946Part VCase StudiesIf we re going to offer a (Free web host)

946Part VCase StudiesIf we re going to offer a way to query the database, then it may as well be via a Web form. Sothe end-to-end view of our task is that we start with a Web form and end up with a picture todisplay. Let s start the design by enumerating the things that need to happen for this to comeabout. We ll need to: 1.Generate (or at least present) the Web form itself. 2.Receive the submitted form data and transform it into appropriate SQL queries for submission to the database. 3.Receive results from the SQL queries. 4.Use the SQL results to decide on the locations and sizes of all the elements in ourgraphic. 5.Actually generate the graphic and send it back to the user. All of the code in this chapter should work with either PHP4 or PHP5, but it assumes that yourPHP installation has access to the gdimage library and is configured to produce PNG images. Any version of gdlater than 1.8, bundled or unbundled, should be OK. (See Chapter 42 fordetails of configuration and installation of gd.) Outline of the CodeOur system contains the following code files: .visualization_form.php:This is essentially a hard-coded form that enables the userto choose two different restrictions on the data in our table. The restrictions chosenmap directly to whereclauses loaded from an auxiliary file called query_clauses.php. .db_visualization.php:This code handles the form data sent by visualization_ form.phpand builds three SQL statements: one with only the first where clause, onewith the second whereclause, and a third with both clauses joined by an and. It col- lects resulting three counts and displays the numbers in a graphic by calling functionsloaded from venn.php. .venn.php:This actually produces the Venn diagram graphic and ships it back to theuser. Its primary function takes as input the three amounts (the sizes of the two sets andtheir intersection), decides the sizes and locations of corresponding circles, and does allthe drawing and shading necessary. For the complicated case of sets that actually havean overlapping area, it uses functions loaded from trig.phpto calculate areas. .trig.php:This code actually calculates the intersection area whenever circles overlap. We discuss these code files in reverse order, from the bottom up. By the way, although we likethis example, we don t want to give the impression that you need to do trigonometry to docomputer graphics in PHP, or even vector graphics in PHP. If you want to understand everybit of this example, then you need to go through the trig, but we encourage those who don tcare to skip the next section ( Necessary trigonometry ). The core of the graphics code itselfis in venn.php, and that example code really is important to understand if you want to do gd-based graphics in PHP. Note54
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Leave a Reply