Connecting Tech Pros Worldwide Help | Site Map

Image Gallery

Newbie
 
Join Date: Nov 2008
Posts: 2
#1: Nov 26 '08
Hi there, I was wandering if anyone can give me help on the following please. I am very new to coldfusion.

I have to create a web page which contains 6 images with text taken from an access database which is already stored on the web server.

If an image is clicked, a new page is opened which displays the image and the description.

Can anybody guide me in the right direction please?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Nov 27 '08

re: Image Gallery


Hi soad789, welcome to Bytes!

What have you managed so far? If you post your code, we can help you with the parts you're stuck on.
Newbie
 
Join Date: Nov 2008
Posts: 2
#3: Nov 27 '08

re: Image Gallery


Hi Acoder. Thanks for the reply. Here's what i'v got so far.



Expand|Select|Wrap|Line Numbers
  1. <body>
  2.  
  3. <cfquery name="qGallery" datasource="sp_gallery" cachedwithin="#CreateTimeSpan(0,0,10,0)#">
  4.     SELECT ID,pic_thumb,pic_x,pic_y,pic_title FROM gallery
  5.     ORDER BY ID;
  6. </cfquery>    
  7.  
  8. <!--- initialize variables --->
  9. <cfset start_day = DateDiff("y","01/01/2000",Now())>
  10. <cfset total_items = 12><!--- total items to display --->
  11. <cfset start_item = (start_day MOD qGallery.recordcount) + 1>
  12. <cfset end_item = start_item + (total_items - 1)>
  13. <cfif end_item GT qGallery.recordcount>
  14.     <cfset end_item = end_item - qGallery.recordcount>
  15. </cfif>
  16. <cfset columns = 4>
  17. <cfset col_tick = 0>
  18. <cfset count = 0>
  19.  
  20. <div align="center">
  21. <table width="70%" border="0" cellpadding="4" cellspacing="0"> 
  22. <tr>
  23.  
  24. <cfif start_item LT end_item><!--- we can do it one loop, the end_item is higher than the start_item --->
  25.  
  26.      <cfloop query="qGallery" startrow="#start_item#" endrow="#end_item#">
  27.         <cfset col_tick = IncrementValue(col_tick)>
  28.         <cfset count = IncrementValue(count)>
  29.         <cfoutput>
  30.             <td width="40"><img src="#pic_thumb#" height="#pic_y#" width="#pic_x#"></td>
  31.             <cfif count EQ total_items>
  32.                 </tr></table>
  33.             <cfelseif col_tick EQ columns>
  34.                 </tr><tr><cfset col_tick = 0>
  35.             </cfif>
  36.         </cfoutput>
  37.     </cfloop>
  38.  
  39. <cfelse><!--- start_item NOT LT end_item - we need two loops - 1st to the end of the recodset, 2nd to the end_item value --->
  40.  
  41.     <cfloop query="qGallery" startrow="#start_item#" endrow="#qGallery.recordcount#">
  42.         <cfset col_tick = IncrementValue(col_tick)>
  43.         <cfset count = IncrementValue(count)>
  44.         <cfoutput>
  45.             <td width="40"><img src="#pic_thumb#" height="#pic_y#" width="#pic_x#"></td>
  46.                 <cfif col_tick EQ columns>
  47.                     </tr><tr><cfset col_tick = 0>
  48.                 </cfif>
  49.         </cfoutput>
  50.     </cfloop>
  51.  
  52.     <cfloop query="qGallery" startrow="1" endrow="#end_item#">
  53.         <cfset col_tick = IncrementValue(col_tick)>
  54.         <cfset count = IncrementValue(count)>
  55.         <cfoutput>
  56.             <td width="40"><img src="#pic_thumb#" height="#pic_y#" width="#pic_x#"></td>
  57.             <cfif count EQ total_items>
  58.                 </tr></table>
  59.             <cfelseif col_tick EQ columns>
  60.                 </tr><tr><cfset col_tick = 0>
  61.             </cfif>
  62.         </cfoutput>
  63.     </cfloop>
  64.  
  65. </cfif><!--- close if start_item LT end_item --->
  66.  
  67. </div>
  68.  
  69. </body>
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Nov 27 '08

re: Image Gallery


You can add a link around the image which links to a page making it unique to the image clicked by passing the ID, e.g.
Expand|Select|Wrap|Line Numbers
  1. <a href="imgLarge.cfm?id=#ID#"><img src="#pic_thumb#" height="#pic_y#" width="#pic_x#"></a>
PS. please use [code] tags when posting code. It makes it easier to read. Thanks!
Reply