selecting 3 images

selecting 3 images

am 10.01.2006 12:13:26 von patrick

Hi all,

I am not very good at sql, so anything remotely beyond simple, it goes
over my head.

I have a table which contains various fields, including 3 image fields.
(image1_id, image2_id, image3_id). Each of these fields contains the id
of an image found in the images table, (id, image).

I need to pull all three images out and use them, which is where I get
stuck. To use just one image, I use the following:

SELECT " . DB_PREFIX . "news.id, tagline, article, image
FROM " . DB_PREFIX . "news
LEFT JOIN " . DB_PREFIX . "images
ON image1_id = " . DB_PREFIX . "images.id
WHERE main='on' LIMIT 1

and I am able to refer to the image as image. But how do I pull out all
three to use them? I hope this is clear enough, let me know if you need
any mor information.

Thanks

Patrick

Re: selecting 3 images

am 10.01.2006 14:28:28 von filip.brugge

This is the easiest one

select a.*
from images a,
news b
where a.id in (b.id_1, b.id_2, b.id_3)

You have to make it work for your database structure of course.

Re: selecting 3 images

am 10.01.2006 14:29:00 von filip.brugge

This is the easiest one

select a.*
from images a,
news b
where a.id in (b.id_1, b.id_2, b.id_3)

You have to make it work for your database structure of course.

Re: selecting 3 images

am 10.01.2006 16:23:15 von patrick

hi thanks for that. but once i have that, how do i use the images? i
cant use image1_id, image2_id, image3_id, I need some way to refer to
the 3 images themselves dont i?