Reply
News with images
Old 12-20-2007, 06:27 PM News with images
Skilled Talker

Posts: 73
Name: Mattias Nordahl
Location: Sweden
Hi!

This is my first time in the database forum
On my website there will be a list of news of what has happened recently. News will be stored in a database (using PHP/MySQL) and only the most recent ones will be shown. So far piece a cake.

Now, heres the problem. Every news will aslo be able to hold a number of images (0-5). Images will be stored in a database table of their own. How would I best store this in the database, since I won't know how many images each news got? I should probably store the images id's with each news, but I won't know how many there are.

And just to clarify, the problem isn't storing the images in my database, but how to link the news to their associated images.

Thanks
lizciz
lizciz is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 12-21-2007, 03:03 AM Re: News with images
chrishirst's Avatar
Super Moderator

Posts: 11,466
Location: Blackpool. UK
I use a seperate table for images and store the ID of the item and the path to the image in each row.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2007, 07:05 AM Re: News with images
Skilled Talker

Posts: 73
Name: Mattias Nordahl
Location: Sweden
I do too. I believe you didn't read my post very carefully. The problem I'm having is not how to store images in my database, but how to link the images to the news they belong to.

Edit:
Hmm, now that I read my own post, where I wrote "link the images to the news" instead of "link the news to their associated images" I realised I can simply add an attibute 'newsID' to each image that tells which news this image belong to

Last edited by lizciz : 12-21-2007 at 07:13 AM. Reason: Realisation
lizciz is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 07:30 AM Re: News with images
chrishirst's Avatar
Super Moderator

Posts: 11,466
Location: Blackpool. UK
Yep.

and I've just noticed my post should have read;
Quote:
store the ID of the newsitem and ...
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-23-2007, 10:59 PM Re: News with images
Average Talker

Posts: 15
each row for each image. (many rows for one news )
skoogo is offline
Reply With Quote
View Public Profile
 
Old 12-29-2007, 04:51 AM Re: News with images
Average Talker

Posts: 24
Name: Nick Cousins
Location: Northern Ireland
Hmmm I would do it like this (but I could be VERY wrong! hehe)

[newsitems table]
uid
title
description
etc..

[images table]
uid
caption
imagefile
etc...

[linkup table]
uid
newsid
imageid

Each row in the linkup table has a newsid (corresponding to a uid in the news items table) and an imageid (corresponding to an uid in the images table).

That way you can have as many images linked to as many news items as you wish.

You can also re-use images in different news items simply by creating more links.
HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Reply     « Reply to News with images
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13851 seconds with 13 queries