13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

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

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

212 Chapter 8 Designing Your <strong>Web</strong> Database<br />

This set of information suggests you need at least three tables in this database:<br />

Customers, Orders, <strong>and</strong> Books.This initial schema is shown in Figure 8.3.<br />

CUSTOMERS<br />

CustomerID<br />

Name<br />

Address<br />

City<br />

1<br />

Julie Smith<br />

25 Oak Street<br />

Airport West<br />

2<br />

Alan Wong<br />

1/47 Haines Avenue<br />

Box Hill<br />

3<br />

Michelle Arthur<br />

357 North Road<br />

Yarraville<br />

ORDERS<br />

OrderID<br />

CustomerID<br />

Amount<br />

Date<br />

1<br />

3<br />

27.50<br />

02-Apr--2007<br />

2<br />

1<br />

12.99<br />

15-Apr-2007<br />

3<br />

2<br />

74.00<br />

19-Apr-2007<br />

4<br />

3<br />

6.99<br />

01-May-2007<br />

BOOKS<br />

ISBN<br />

Author Title Price<br />

0-672-31697-8<br />

Michael Morgan<br />

Java 2 for Professional Developers<br />

34.99<br />

0-672-31745-1<br />

Thomas Down<br />

Installing GNU/Linux<br />

24.99<br />

0-672-31509-2<br />

Pruitt.et al.<br />

Teach Yourself GIMP in 24 Hours<br />

24.99<br />

Figure 8.3<br />

The initial schema consists of Customers, Orders, <strong>and</strong> Books.<br />

At present, you can’t tell from the model which books were ordered in each order.We<br />

will deal with this situation shortly.<br />

Avoid Storing Redundant Data<br />

Earlier, we asked the question:“Why not just store Julie Smith’s address in the Orders<br />

table?”<br />

If Julie orders from Book-O-Rama on a number of occasions, which you hope she<br />

will, you will end up storing her data multiple times.You might end up with an Orders<br />

table that looks like the one shown in Figure 8.4.

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

Saved successfully!

Ooh no, something went wrong!