Coldfusion CFLOOP multiple lists.

Coldfusion / Mysql

I have a database field "photos" that holds a comma delimited string of photo URL's and feeds a slideshow.   the code below works,  but I also now have a field "thumbs" that contains another comma delimited string of photo URL's. I want to populate these as my thumbnail images instead of just using the large image as I have in the below code snip.  How would I accomplish this? Any help appreciated.


<!---this code works but doesnt uses the main photo as a thumbnail--->

<cfloop list="#photos#" index="ListItem" delimiters=",">
	
     <cfoutput>
	 <a class="rsImg" data-rsh="500" data-rsBigImg="#trim(ListFirst(ListItem))#" href="#trim(ListFirst(ListItem))#" alt="#details.AddressNumber# #details.AddressStreet#, #details.City#, #details.State# #details.zipcode#">
		<img width="96" height="72" class="rsTmb" src="#ListItem#" /></a> 
	</cfoutput>

</cfloop>




<!---this code doesnt work--->

<cfloop list="#photos#" index="ListItem" delimiters=",">
<cfloop list="#thumbs#" index="ListItem2" delimiters=",">
	

	 <a class="rsImg" data-rsh="500" data-rsBigImg="#trim(ListFirst(ListItem))#" href="#trim(ListFirst(ListItem))#" alt="#details.AddressNumber# #details.AddressStreet#, #details.City#, #details.State# #details.zipcode#">
		<img width="96" height="72" class="rsTmb" src="#ListItem2#" /></a> 

	</cfloop>
	</cfloop>

Open in new window

Bang-O-MaticAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
Assuming there's a 1-to-1 relationship between the list of large image url's and the list of thumbnail url's,  you don't need a double list loop. Instead, use a "from/to" loop and use the position to grab the desired elements. (Also, converting the lists to arrays makes for easier code IMO ;-)

<!--- both lists MUST be the same size or loop may error --->
<!--- convert lists to arrays -->
<cfset photoArray = listToArray(photos, ",")>
<cfset thumbArray = listToArray(thumbs, ",")>

<cfloop from="1" to="#arrayLen(photoArray)#" index="pos">

     <!--- extract current set of big/thumb image --->
    <cfset bigImage = photoArray[pos]>
    <cfset thumbImage = thumbArray[pos]>

	<!--- 
		create link with big image and thumbnail variables here 
	--->	
</cfloop>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bang-O-MaticAuthor Commented:
Works perfect! As always, Thanks for your help!
_agx_Commented:
Anytime. Glad it helped :-)

(As noted in the comments, obviously it's assumed the lists are the same size.  If it's possible they may not be, add some error handling).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.