on 2/28/02 2:21 AM, Monty at [EMAIL PROTECTED] appended the following bits
to my mbox:

> I have an Image table in a MySQL database that will be used to store the
> location of all images used on my site. Some images will relate to an
> Article table (article.id) and some images may relate to a Member table
> (member.id).
> As it's possible that there may be an article.id that is the same as a
> member.id, I am considering adding two fields to the Image table (article_id
> and member_id) one of which will be left blank for each record, depending on
> the image's relation. For example, if "mypic.jpg" is related to article.id
> 288 in the Article table, then I would insert 288 into the article_id field
> in the Image table but leave the member_id field blank.

Personally, I'd use translation or many to many relationship tables.

You'd have five tables total:

images, articles, articles_images, members, members_images

The schema for the articles_images table would be:

record_id (primary key sequence/auto-increment)

If the RDBMS supports it, make a unique key on the combo of (article_id,

If you're in an article, you can then get the images by doing a:

SELECT col1,col2,col3 FROM articles_images AS ai LEFT JOIN images AS i ON
ai.image_id=i.image_id WHERE article_id="CURRENT_ARTICLE_ID"

This allows you to have one source of images and allows you to have multiple
images used in an article or multiple articles using the same image.

You could then also setup a members_images in the same way.

Hope that helps.


    while ($self != "asleep") {

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to