Resources

CSS, the Missing Manual David Sawyer McFarland
PHP and MySQL Larry Ulman
Manga Guide to Databases Shoko Azuma

useful programming resources

W3 Schools programming resources

Tiztag programming resources

About.com

Web site security rules

An HTML validation tool, Very Important

Lists and CSS styles elegantly explained

Step by step lessons in PHP programming

Web Developer Notes

SQL Zoo


Useful tools

Text Wrangler - General Purpose text editor

Transmit Text Edit and FTP client

The Total Validator validation tool


Other stuff I write

A Dark and Stormy Knight

Change

Building a cool website using HTML, PHP and MySQL

Joins

now to the point of the last several pages. What is the point of having all these tables? You want the information you want, and you don't want to go shuffling from table to table looking for it. If you want to know who has what book out and when is it due, you want information that looks like this:

mysql> select books.title, concat(patron.efname,' ',patron.elname) as borrower, -> volumes.due_date as 'when due' from books, patron, volumes where -> books.book_id=volumes.book_id -> and volumes.checked_to_Patron=patron.patron_id; +-------------------------------------+-----------------------+------------+ | title | borrower | when due | +-------------------------------------+-----------------------+------------+ | Anatomy of Revolution | Carrot Ironfounderson | 2010-11-13 | | Enchanted INC | Penny LaVache | 2010-11-18 | | Hitchhikers Guide to the Galaxy | Sheldon Cooper | 2010-10-28 | | Humans | Howard Melman | 2010-11-15 | | In Defense of Women | Sam Vimes | 2010-11-10 | | Inside the Third Reich | Sam Vimes | 2010-11-10 | | Life the Universe and Everything | Howard Melman | 2010-11-15 | | Making Money | Howard Melman | 2010-11-15 | | Microbe Hunters | Carrot Ironfounderson | 2010-11-13 | | North America | Rajiv Kulliphipothong | 2010-11-18 | | Revenge of Kali Ra | Sam Vimes | 2010-11-10 | | Siege of Vicksburg | Carrot Ironfounderson | 2010-11-13 | | Sins for Father Knox | Sam Vimes | 2010-11-10 | | Skeleton in the Closet | Sam Vimes | 2010-11-10 | | So Long and thanks for All the Fish | Howard Melman | 2010-11-15 | | Wealth of Nations | Carrot Ironfounderson | 2010-11-13 | | Whom the Gods would Destroy | Leonard Hoffstedder | 2010-11-18 | +-------------------------------------+-----------------------+------------+ 17 rows in set (0.00 sec)

First, Our library is organized into several tables. We have an authors table, a topics table, a books table, a users table, a books checked out table, and a books-author relation table. The point of all this is to guarantee internal integrity within the data. For instance, we have this author:

  mysql> select books.title, concat(authors.efname,' ',authors.elname)
          -> as author,
          -> topics.topic from books inner join topics using(topic_id)
          -> inner join bookswritten using(book_id)
          -> inner join authors using(writer_id) where authors.writer_id=12
          -> order by topics.topic;
+----------------+-----------------+--------------+
| title          | author          | topic        |
+----------------+-----------------+--------------+
| Humans         | Donald Westlake | Fantasy      | 
| Why me?        | Donald Westlake | Mystery      | 
| High Adventure | Donald Westlake | Romance      | 
| Kahawa         | Donald Westlake | Spy Thriller | 
+----------------+-----------------+--------------+
4 rows in set (0.76 sec)

Same guy, lots of different styles. He wrote lot of books. Whenever we added a new one, all we did is added the one volume to the books table, links in the relation tables and we are done. He just died this year, so if we had biographical information on him, all that would need to change is that, there is no need to change the rest of the data base, with all its opportunities for error. We just change the one bit of information in the one place that has universal application with all his data.

Since all that data is in different tables, we need a way to bring it together. That is the function of the join.

There are two flavors of join. One is the plain join It can be called inner join. (I usually use "inner Join" in my work. ) It reports on data that meets all the criteria. For example, if Steven King were on my list of Authors, and since I don't have any books by Steven King, he would not show up on my inner join.

The other form of join is the left or right join. These joins show data that shows up on one table, even if there is no related data in the second table.

  mysql> select * from authors where writer_id=34;
+-----------+--------+--------+
| writer_id | efname | elname |
+-----------+--------+--------+
|        34 | Steven | King   | 
+-----------+--------+--------+
1 row in set (0.07 sec)

  mysql> select books.title, concat(authors.efname,' ',authors.elname)
          -> as author,
          -> topics.topic from books inner join topics using(topic_id)
          -> inner join bookswritten using(book_id)
          -> inner join authors using(writer_id) where authors.writer_id=34;
Empty set (0.14 sec)

  mysql> select books.title, concat(authors.efname,' ',authors.elname)
          -> as author from books left join bookswritten using(book_id)
          -> right join authors using(writer_id) limit 55,10;
+------------------------------------+------------------+
| title                              | author           |
+------------------------------------+------------------+
| Flashman and the Mountain of Light | George Frazier   | 
| Memoirs                            | Ullysses Grant   | 
| Memoirs                            | Tecumsah Sherman | 
| Skeleton in the Closet             | MC Beaton        | 
| NULL                               | Steven King      | 
+------------------------------------+------------------+
5 rows in set (0.04 sec)

Left and right joins can be useful in places where you need to know where there is empty data. For example, if you have rental property, the apartment doesn't go away when the tenant leaves. Most of the time.

I have been talking about data integrity on several occasions. Data integrety is the point of all this. The goals of data integrety are:

Most of the really important work of web pages is in the design and organization of the data you wish to present. It is also the hardest part of any web project, the part you need to spend the most time thinking over. But now you have the foundation in, you can start thinking of the next part: The HTML frame.

| page 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 |