Examples


On the CD In this section, we show some examples of diagrams and code fragments. The samples shown here are simple php and asp code. The CD-ROM contains the code in the folder named chapter1code.

Entity-Relation, Process, and Storyboard Diagrams

The term entity is a fancy name for thing. Entities might be concrete things that exist in a business or organization, such as customers and products, or they might be abstract or ephemeral, such as an order number-product number pair that represents part of a customer’s order. Any single entity is represented by certain information, and the items of information are called attributes, properties, or fields, depending on the context. The technical term relationship has the regular, “English” meaning. The two-table database described in the preceding section is represented by the ERD shown in Figure 1.2.

Notice that we have made up names for all the fields that are now legal names with no internal blanks as opposed to descriptions. The line connecting the two boxes represents the relationship between the two tables. The markings indicate that each product—that is, each record in the catalog table—refers to exactly one category record. Put another way, a category can have many products. More than one product can be in a category. It, however, does not guarantee that each category has at least one product.

A slightly more complex database is shown in Figure 1.3. This database supports a quiz show application using three tables.

click to expand
Figure 1.3: Entity relationship diagram for quiz show database.

The history table keeps records of the play of the game, with information on which player answered which question when and with what result. The history table serves as what is commonly called a “join table” to relate the question and the player entities. There is a one-to-many relationship between the question table and the history table and the player table and the history table. There can be none, one, or many entries in the history table for each question. Similarly, there can be none, one, or many entries in the history table for each player.

The process diagram in Figure 1.4 for the quiz show application reveals how the application is to function.

click to expand
Figure 1.4: Process diagram for quiz show application.

Notice that there are two agents; that is, two types of users. Players play the game, with that process making use of three distinct data stores. These data stores correspond to the tables of the database, but that implementation detail is not critical in the process diagram. Editors input, delete, and modify questions.

The book will show you the inner workings of the quiz show application in PHP and ASP versions, and another application, a slightly more elaborate online store. Figure 1.5 shows a storyboard indicating the distinct files (scripts) we designed and wrote for the quiz show. You will learn about this application in Chapter 15, “Quiz Show.” For now, just look at the diagram as an example of representing an application made up of multiple files. The arrows represent one script calling another. One type of call is for handling a form, and another type is as the target of a hyperlink. Form handling is represented by thick arrows, and links by thin arrows. With this information, this diagram shows many things. First, there are eight scripts. One script, called opendbq, is an include/required file. This special file type will be explained later. The diagram also indicates the relationship among the files. For example, the diagram indicates that the choose category script invokes the ask question script to handle a form. The ask question script has a link back to the choose category script. The choose category script also has links from check answer and clear tables. There are links in both directions between the choose category script and the show scores script.

click to expand
Figure 1.5: Storyboard for quiz show application.

Code Examples

We now look at simple code examples of PHP and ASP script.

An example of PHP coding:

    <html>     <head><title>first PHP </title></head>     <body>     <?php     $today=  Date('d-m-Y');     $now = Date('g:i');     print ("Hello World!<BR> Today is $today");     print ("<br>The time is $now");     ?>     </body>     </html>

The standard HTML boilerplate (we provide a review of HTML in the next chapter) is given in the PHP file as regular HTML. The <?php starts the PHP section. You can omit the PHP if the file has extension .php. The four lines within the delimiters do the following tasks:

  1. Invoke the built-in Date function with the parameter specifying the format for the date. All variables in PHP start with the dollar sign.

  2. Invoke the built-in Data function (again) with a different parameter to get the time.

  3. Invoke the print function to output the string that is the argument of the function call to the HTML document. The PHP interpreter will use the value of the variable $today.

  4. Invoke the print function again. In this case, the PHP interpreter will use the value of the variable $now.

The following ASP script produces a similar (although not identical) HTML document:

    <%@ Language="JavaScript" %>     <html>      <head> <title>Hello World, Active Server Pages!     </title>         </head>     <body>     <%      var now = Date();     Response.Write(      "Hello World!<BR> The date and time now is " + now);     %>     </body>     </html>

One of the ASP objects is the Response object. It has a method named Write. Thus, Response.Write is the ASP equivalent of PHP’s print. Variables in the ASP/JavaScript system can start with any alphabetic character. However, this is one reason why we cannot use the PHP trick of embedding variables within strings. The plus sign is the string concatenation system in JavaScript.

It is possible to write an even simpler “Hello, World” program. These programs do something on the server, namely calling the date functions, and it is doing something on the server that characterizes middleware.




Creating Database Web Applications with PHP and ASP
Creating Database Web Applications with PHP and ASP (Charles River Media Internet & Web Design)
ISBN: 1584502649
EAN: 2147483647
Year: 2005
Pages: 125
Authors: Jeanine Meyer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net