Display random thumbnail for it's category

Thread Solved

Join Date: May 2008
Posts: 23
Reputation: Besherek is an unknown quantity at this point 
Solved Threads: 0
Besherek Besherek is offline Offline
Newbie Poster

Display random thumbnail for it's category

 
0
  #1
May 3rd, 2009
Hi guys,

I think I may have complicated matters for myself with this one.

I'm making an image gallery, which is built based on a hierarchy.

I have no problem outputting the images directly in their specific category.

The problem I'm having is I'm trying to call 1 thumbnail from the database that relates to the top level album title (country_title).

I think it's my SQL or perhaps my table structure that's failing me on this one.

My table structure is as follows:

country
country_id
country_title

state
state_id
state_title
country_id

suburb
suburb_id
suburb_title
state_id

description
description_id
description_thumbnail
description_photo
description_date
state_id

So, the first page will have a list of countries with the country title displayed with a random thumbnail called from the description table that relates to that country.

Here is a rough example of the code i'm using, there is no html formatting as im not sure how i'm going to output it.

  1. <?php
  2. // set up SQL statement to output data
  3. $main_country_query = mysql_query(" SELECT DISTINCT country_id, country_title FROM photo_country");
  4. // Main Country Loop
  5. while( list( $country_id, $country_title ) = mysql_fetch_row( $main_country_query ) )
  6. {
  7. // thumbnail query
  8. if ( mysql_num_rows( $main_country_query ) > 0 )
  9. {
  10. $main_thumb_query = mysql_query("SELECT country_title, description_thumbnail FROM country, state, suburb, description WHERE country.country_id = state.country_id AND state.state_id = suburb.state_id AND suburb.suburb_id = description.suburb_id AND country.country_id = {$country_id} LIMIT 1");
  11. while( list( $country_title, $description_thumbnail ) = mysql_fetch_row( $main_thumb_query ) )
  12. {
  13. echo $country_title."\n";
  14. echo "<img src='".$description_thumbnail."' />\n";
  15.  
  16. // set up SQL statement to count state categories
  17. $state_count_query = mysql_query("SELECT * FROM country, state WHERE country.country_id = state.country_id AND state.country_id = {$country_id}");
  18. $state_count = mysql_numrows($state_count_query);
  19. echo "states ".$state_count;
  20. }
  21. }
  22. }
  23. ?>

Can anyone clue me in?

The output is displaying all the thumbnails in relation with the first country_id and only displaying the first country_title repeatedly with the thumbnails.

Thanks in advance!
Last edited by Besherek; May 3rd, 2009 at 12:24 am.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 23
Reputation: Besherek is an unknown quantity at this point 
Solved Threads: 0
Besherek Besherek is offline Offline
Newbie Poster

Re: Display random thumbnail for it's category

 
0
  #2
May 4th, 2009
All good, I've worked it out.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC