using loop around a query

hello,

first off, here are my 2 queries:

<!--- query for veiws and other ID info --->
<cfquery name="GetMostViews" datasource="DB" maxrows="5">
select Top 5 Tables.Maintable, Tables.ID, LinkInfoID, Views
from Clicks_#cookie.regulator#
left join Tables on Clicks_#cookie.regulator#.TableNameID = Tables.ID
</cfquery>

<!--- query for veiws and other ID info --->
<cfloop query="GetMostViews">
<cfquery name="GetLinkInfo" datasource="DB">
select LinkURL, LinkTitle
from #GetMostViews.MainTable#
where ID = #GetMostViews.LinkInfoID#
</cfquery>
</cfloop>

what i need these two queries to accomplish is for the 2nd query to use MainTable and LinkInfoID from the 1st query to retrieve info. in theory it should loop and cycle thru the 5 results from the 1st query, but it's not doing so. any thoughts?

thanks
steve
sdowns1122Asked:
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.

mrichmonCommented:
Well the second query is gettin grun 5 times and each time the output is overwriting the previous time.

Maybe you want somehting like:

<cfquery name="GetLinkInfo" datasource="DB">
<cfif GetMostViews.currentRow NEQ GetMostViews.RecordCount>
select LinkURL, LinkTitle
from #GetMostViews.MainTable#
where ID = #GetMostViews.LinkInfoID#
UNION
<cfelse>
select LinkURL, LinkTitle
from #GetMostViews.MainTable#
where ID = #GetMostViews.LinkInfoID#
</cfif>
</cfquery>
0

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
kkhippleCommented:
Have you tried outputting the information you have within the loop?
You dont need to reference #GetMostViews# again within your query

<!--- query for veiws and other ID info --->
<cfquery name="GetMostViews" datasource="DB" maxrows="5">
select Top 5 Tables.Maintable, Tables.ID, LinkInfoID, Views
from Clicks_#cookie.regulator#
left join Tables on Clicks_#cookie.regulator#.TableNameID = Tables.ID
</cfquery>

<!--- query for veiws and other ID info --->
<CFOUTPUT query="GetMostViews">
<cfquery name="GetLinkInfo" datasource="DB">
select LinkURL, LinkTitle
from #MainTable#
where ID = #LinkInfoID#
</cfquery>

#LinkURL# #LinkTitle#
</CFOUTPUT>
0
sdowns1122Author Commented:
thanks for the help guys. i ended up placing the results into an array.
0
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
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.