You need to add an additional table, favorites.

It should have three columns:

favoriteID INT,
userID INT,
favoriteTypeID INT REFERENCES FavoriteType.

Plus the additional column for the rating, assuming it's associated with a
favorite.

Each row represents a single preference (this way users can have an
arbitrary number of preferences). Each user would be associated with
multiple rows in the table. The favoriteID is so that you can
delete/update favorites easily; you want to be able to talk about a
particular row. You might want a SELECT like this: "SELECT * FROM
favorites WHERE userID = $id ORDER BY rating DESC LIMIT 0,10" to get the
top ten favorites for user identified by $id.

You might also want to make an additional table, favoriteType, unless each
favorite is completely unique (in which case the third column in the table
above would have VARCHAR or TEXT type). (You should avoid that kind of
design if possible, because most likely anything you want to rank is going
to have similarities across users)

favoriteTypeID INT
favoriteLabel VARCHAR

You should do some research on normalization and database design. There
are some good books on the topic.

Quinten

On Sun, 11 Aug 2002, david wrote:

> Date: Sun, 11 Aug 2002 00:43:14 -0400
> From: david <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: MySQL database design, one column, 10 entries?
>
>
> I am creating several tables in MySQL and linking via primary keys. I am held
> up on one issue, for one row in one table i have a column 'favorites' where i
> want to hold up to 10 unique entries, how do i implement this?
>
>
> userTable
> userId varchar(20)
> name varchar(30)
> email varchar(40)
>
> preferences
> userId varchar(20)
> styles varchar(20)
> favorites ????????
>
>
>         preferences
> userId          styles          favorites               rating
> 01              'modern'        '#1 sleek'              15
>                                 '#2 ultra-sleek'        20
>                                 '#3 un-sleek'           12
>                                 '#4 plain'               9
>                                  etc, up to 10 or so.
>
> 02              'gothic'        '#1 dark'               21
>                                 '#2 tall'               4
>                                 '#3 scary'              2
>                                 etc, etc,...
> I can't just make it a really long varchar(1000) because of the other columns
> that act on the same data. I hope that this is an appropriate question for
> this MySQL list.
> TIA
>
> -david
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to