Re: displaying repetitive results
| From: | Greg Donald | Date: | Wed, 10 Nov 2004 21:52:40 +0000 |
| Subject: | Re: displaying repetitive results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201724@lists.php.net to get a copy of this message | ||
On Wed, 10 Nov 2004 09:04:27 -0900, Chris Lott <chris.lott@gmail.com> wrote:
> Given a database query thats returns results from a linking (or xref)
> table which includes repetition because of the joins:
>
> +----+--------------------------+----------+
> | id | title | subject |
> +----+--------------------------+----------+
> | 1 | Collected Poems of Keats | poetry |
> | 2 | Spy High | suspense |
> | 3 | Sci Fi Spies | suspense |
> | 3 | Sci Fi Spies | sci-fi |
> +----+--------------------------+----------+
>
> What is the best way to go about displaying this for the user so that
> the record looks "complete":
>
> ID: 3
> title: Sci Fi Spies
> Subjects: suspense, scifi
You might normalize the data a bit.
I'd go with three tables: books, subjects, and a books_subjects_xref
table. The subjects table would contain the subject_id and the
subject. The books table would contain the book_id and book_title.
The books_subjects_xref table will contain the book_id and subject_id,
with a two-field unique constraint on book_id and subject_id. You
would have an entry for each subject a book is in.
As far as the sql, I'd suggest something but you didn't say what db
you're using. Looks like MySQL output but I could be wrong.
--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/