05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Two HTML forms are needed to populate the database tables. One form provides<br />

the site administrator with the means to add category IDs, titles, and descriptions.<br />

The second form, used by the self-registering businesses, collects the business contact<br />

information and permits the registrant to associate the listing with one or more<br />

categories. A separate page displays the listings by category on the web page.<br />

Database Tables<br />

There are three tables: businesses to collect the address data for each business,<br />

categories to name and describe each category, and an associative table called biz_<br />

categories to relate entries in the other two tables to each other. These tables and<br />

their relationships are shown in Figure 8-3.<br />

Businesses<br />

Business ID<br />

Name<br />

Address<br />

City<br />

Telephone<br />

URL<br />

Figure 8-3. Database design for business listing service<br />

Example 8-2 contains a dump of the table schema in MySQL format. Depending on<br />

your database’s features, the schema may have to be altered slightly.<br />

Example 8-2. Database schema<br />

# --------------------------------------------------------<br />

#<br />

# Table structure for table 'biz_categories'<br />

#<br />

CREATE TABLE biz_categories (<br />

business_id int(11) NOT NULL,<br />

category_id char(10) NOT NULL,<br />

PRIMARY KEY (business_id, category_id),<br />

KEY business_id (business_id, category_id)<br />

);<br />

1,n<br />

Biz_Categories<br />

Business ID<br />

Category ID<br />

1,n<br />

# --------------------------------------------------------<br />

#<br />

# Table structure for table 'businesses'<br />

#<br />

CREATE TABLE businesses (<br />

business_id int(11) NOT NULL auto_increment,<br />

name varchar(255) NOT NULL,<br />

Categories<br />

Category ID<br />

Title<br />

Description<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Sample Application | 203

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

Saved successfully!

Ooh no, something went wrong!