A
Anonymous
Guest
Hello everyone, new here.
I'm finding this hard to explain.
Scenario.
I have 2 tables, one for galleries and one for images. The gallery table holds the info for the gallery owner. The images table holds the image info linked by the galleryID.
I want to query the image table so that I select just the first image from each gallery. Images are uploaded at random by users so the galleryID is random in the images table depending on who uploaded and when.
Eg. The table may look like this....
ID |GalleryID|filename ( letters used to keep it simple )
1 | 1 | xyz
2 | 4 | abc
3 | 1 | xxx
4 | 2 | yyy
5 | 4 | zzz
6 | 3 | aaa
7 | 2 | bbb
8 | 3 | ccc
So, I need to just get the filename for the first instance of each gallery.
1- xyz 2- yyy 3- aaa 4- abc
So far I have this query......
.... and to display this.....
This of course displays all images.
Does anyone know how I can code this to just select the first image of each gallery.
Hope this makes some sense.
Thanks everyone.
Regards, Paul
I'm finding this hard to explain.
Scenario.
I have 2 tables, one for galleries and one for images. The gallery table holds the info for the gallery owner. The images table holds the image info linked by the galleryID.
I want to query the image table so that I select just the first image from each gallery. Images are uploaded at random by users so the galleryID is random in the images table depending on who uploaded and when.
Eg. The table may look like this....
ID |GalleryID|filename ( letters used to keep it simple )
1 | 1 | xyz
2 | 4 | abc
3 | 1 | xxx
4 | 2 | yyy
5 | 4 | zzz
6 | 3 | aaa
7 | 2 | bbb
8 | 3 | ccc
So, I need to just get the filename for the first instance of each gallery.
1- xyz 2- yyy 3- aaa 4- abc
So far I have this query......
Code:
$query = sprintf("SELECT * FROM wp_ngg_gallery INNER JOIN wp_ngg_pictures ON wp_ngg_gallery.gid=wp_ngg_pictures.galleryid ");
$result = mysql_query($query);
$gallery = mysql_fetch_array($result);
.... and to display this.....
Code:
<?php do{ ?>
<div>
<a href="http://www.mysite/<?php echo $gallery['name']; ?>"><img src="http://www.mysite/<?php echo $gallery['path'] . "/thumbs/thumbs_" . $gallery['filename']; ?>" title="<?php echo $gallery['title']; ?>" alt="<?php echo $gallery['title']; ?>" width="100" height="75" /></a>
</div>
<?php } while ($gallery = @mysql_fetch_array($result)); ?>
This of course displays all images.
Does anyone know how I can code this to just select the first image of each gallery.
Hope this makes some sense.
Thanks everyone.
Regards, Paul