MySQL Forums
Forum List  »  PHP

Re: Mutual Matches
Posted by: Bill Karwin
Date: April 21, 2006 06:42PM

Here are a couple of good books:

"PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide"
by Larry Ullman
http://www.amazon.com/gp/product/0321186486/

"PHP and MySQL Web Development (3rd Edition)"
by Luke Welling, Laura Thomson
http://www.amazon.com/gp/product/0672326728/

I've looked through the latter, and I include the former just because I like the Peachpit series.

A compound key makes it so that the table can't have two identical rows. So you can't insert two rows both with userID = 27 and userFav = 43.

The key also implicitly forms an index on the fields, which will help speed up searches and joins.

Assuming you use InnoDB tables, you can also make each column individually reference a users table, which will prevent invalid ID's from being entered.

So the table would look like this:

CREATE TABLE favorites (
userID INTEGER NOT NULL REFERENCES users (userID),
userFav INTEGER NOT NULL REFERENCES users (userID),
PRIMARY KEY (userID, userFav)
) ENGINE=InnoDB;

Regards,
Bill K.

Options: ReplyQuote


Subject
Written By
Posted
April 21, 2006 04:22PM
April 21, 2006 05:12PM
April 21, 2006 05:29PM
Re: Mutual Matches
April 21, 2006 06:42PM
April 23, 2006 12:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.