PDA

View Full Version : How to do this efficciently?


iceflyin
10-04-2007, 02:13 AM
Ok, heres the deal... I have to associate users with each other, and allow them to confirm/ignore association requests.

So, my original plan was to create a MySql table like this: User, associate, and status.

When a user requests to be associated with another user, the data is inserted. When the second user accepts. Theres two entries, one for each user. The status on both becomes 1, instead of 0... So they display.

A users associates are displayed on profiles with this psedocode...
$associates = mysql_query("SELECT * FROM associates WHERE user=$theProfileBeingViewed", $conn);


Another idea of mine is to make a table like this...

userid1, userid2, status1, and status2
(Status Eg:0=waiting, 1=associated, 2 = ignore.

Then to list the associations on the profiles... Something like this... Psedocode.

$associates = mysql_query("SELECT * FROM associates WHERE user1=$user OR user2=$user", $conn);

Fumigator
10-04-2007, 04:06 AM
Your first design is good, your second design sucks (it isn't normalized).

iceflyin
10-04-2007, 04:11 AM
Yea, I built it with the first design, even though it takes more space, it's faster.

Btw, whats "normalized" mean in this context?