Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using loop around a query

Posted on 2004-10-25
3
Medium Priority
?
174 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:sdowns1122
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 140 total points
ID: 12401079
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
 
LVL 5

Assisted Solution

by:kkhipple
kkhipple earned 140 total points
ID: 12401151
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
 

Author Comment

by:sdowns1122
ID: 12402248
thanks for the help guys. i ended up placing the results into an array.
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question