Jump to content

Query question - Probably simple


TileGuy

Recommended Posts

Good afternoon everyone.

 

I'm using Server version: 5.0.90

 

I'm designing a website for Tile (go figure).

We sort our "series" of tiles into "collections".

 

I'm attempting to make a page, that shows a preview of all series within a collection.

 

This is where I'm at presently:

 

SELECT series.seriesID, series.seriesName, plogger_pictures.id

FROM series, plogger_pictures

WHERE series.collection = colname AND plogger_pictures.parent_album = series.installalbum

ORDER BY series.seriesName ASC

 

colname is the url variable that specifies what collection is to be loaded.

 

The query "works" but returns every photo i have, sorted by series, for the url provided collection.

 

I just need one row per series, with a random plogger_pictures.id from the same plogger.parent_album.

 

I would apreciate any help or suggestions.  Thanks for your patience with the newbee.

 

Thanks

 

TileGuy

Link to comment
Share on other sites

$series_ids = db_query("SELECT id FROM series");

foreach ($series_ids as $series_id) {
  $images_for_series = db_query("SELECT image_something FROM images WHERE series_id = " . db_quote($series_id));
  $random_image_from_series = array_rand($images_for_series);
  do_something($random_image_from_series);
}

 

Hope that helps!

Link to comment
Share on other sites

I just need one row per series

 

 

SELECT series.seriesID, series.seriesName, plogger_pictures.id

FROM series, plogger_pictures

WHERE series.collection = colname AND plogger_pictures.parent_album = series.installalbum

GROUP BY series.collection

ORDER BY rand(), series.seriesName ASC

 

 

Link to comment
Share on other sites

awesome, thank you both. 

 

Ignance is close but I would ideally get a list of all series in that collection each combined with a randome photo.

 

Dabar... your code is beyond me and I look forawrd to sitting down tonight and learning how it works.

 

Thanks for the quick responses.

 

TileGuy

Link to comment
Share on other sites

  • 4 weeks later...

Table 1 = series

Fields:

seriesID  int(5) primary

seriesName varchar(25)

collection int(2)

installalbum int(7)

(there are more fields, but these are the relavent fields)

 

Table 2 = plogger_pictures

Fields:

path varchar(255)

parent_album int(11) <--- this field should join with series.installalbum

id int(11) Primary

 

Idealy, the sql would return All series within a collection (say collection # 1)

 

It would then match 1 picture from plogger_pictures (with the same album id) and join it with the relevant series.

 

The intention is to create a list of series within a collection, with a random photo from each series gallery displayed.

 

Is there help for me yet?

 

thanks everyone

 

TileGuy

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.