Question

Cfoutput inside a loop?

Asked by: R_Hos

Is it posible, not to mention good practice to use the output from a query inside a loop?  I am attempting to do that now and instead of getting the enitre list like I was expecting I get 1040 instances of the first page.  



<!-- Query of the products in our database --->
<cfquery name="products" datasource='nwchicagocdsco406'>
      SELECT Products.ProductName
      FROM Products
      GROUP BY Products.ProductName;
</cfquery>

<cfset specialCharacters = " ()-">
<cfoutput query="products">
THIS SHOULD WORK ... SHOULD.  <br>
      #products.recordcount# <br>
      <cfset QueryEnd = #products.recordcount#>
      <cfset DrugName = 'Vioxx'>
      <cfset NameLong = len(#ListFirst(Products.productname,specialCharacters)#)>

            <cfloop from="1" to="1040" index="i">
                  <!--- Grab the page --->
                  <cfhttp url="http://mysite.com/productinfo.jhtml?particularDrug=#ListFirst(Products.productname,specialCharacters)#" resolveurl="no">
                  <hr>
                  <!--- Loop to find the url links on the grabbed page --->
                  <cfset PTR = findnocase("Dosage Forms", cfhttp.FileContent, 1)>
                  <cfset END = len(cfhttp.FileContent)>
                  <cfset EndOfLoop = FindnoCase('<table width="100%"', cfhttp.FileContent, ptr)>
                  #i# <br>
                  <!-- PTR = #PTR#, EOL = #EndOfLoop# <br>  -->

                        <cfloop condition="PTR LT EndOfLoop and ptr GT 0">
                              <cfset hit = findnocase("#ListFirst(Products.productname,specialCharacters)#", cfhttp.FileContent, PTR)>
                              <!--       HIT = #hit# <br> -->
                                    <cfif hit GT 0>
                                    <cfset EndURL = findnocase('</td>', cfhttp.FileContent, hit)>
                                    <cfset EndURL = (EndURL)>
                                    <cfset HowLong = (EndURL - hit)>
                                    <cfset Links = mid(cfhttp.FileContent, (hit), (HowLong))>
                                    <!--       DEBUG INFO: Links: #endURL#, #HowLong#, -->#Links#,
            
                                    <cfset hit2 = findnocase('000">', cfhttp.FileContent, PTR)>
                                    <cfset EndCount = findnocase("</td>", cfhttp.FileContent, hit2)>
                                    <cfset HowLongCount = (EndCount - hit2)>
                                    <cfset Count = mid(cfhttp.FileContent, hit2 + 5, HowLongCount)>
                                    #Count#,
            
                                    <cfset Hit3 = findnocase("$", cfhttp.FileContent, PTR)>
                                    <cfset EndPrice = FindnoCase("</td>", cfhttp.FileContent, hit3)>
                                    <cfset HowLongPrice = (EndPrice - Hit3)>
                                    <cfset Price = mid(cfhttp.FileContent, hit3, howlongprice)>
                                    #Price# <BR>
            
                                    <cfset PTR = hit + 1>
                              <cfelse>
                                    DUMPED THE LOOP! <Br>
                                    <cfset PTR = 0>
                              </cfif>
                        </cfloop>

                  <cfset Hit4 = findNoCase('Drug Manufacturer:</b>', cfhttp.filecontent, EndOfLoop)>
                  <cfset EndManufacturer = findnocase('<p><b>', cfhttp.FileContent, hit4)>
                  <cfset HowLongMan = (EndManufacturer - Hit4)>
                  <cfset Manufacturer = mid(cfhttp.FileContent, hit4, howlongman)>
                  #Manufacturer# <br>
            
                  <cfset Hit5 = findNoCase('Common Uses:</b>', cfhttp.FileContent, EndOFLoop)>
                  <cfset EndUses = FindNoCase('<p><b>', cfhttp.FileContent, Hit5)>
                  <cfset HowLongUses = (EndUses - Hit5)>
                  <cfset Uses = mid(cfhttp.FileContent, hit5, howlonguses)>
                  #Uses# <br>
                  
                  <cfset i = (i + 1)>
                  
            </cfloop>
      </cfoutput>

Thanks in advance!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-09-02 at 13:29:25ID20726933
Tags

loop

,

hit5

Topic

ColdFusion Application Server

Participating Experts
3
Points
250
Comments
5

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Cfquery within a Cfoutput
    I have a problem creating a menu page. What happens is the user selects a reports and from a table the report is generated. Each field that makes the report can contain a list, and the list has to be generated from SQL. The first part works fine, getting the lists and assig...
  2. Problem with CFLOOP and CFOUTPUT
    In the following code, I am retrieving the Date of Birth pre-filled for each person that is related to one another. The like field is the Emp_SSN field. That reflects the Social Sec. No. of the parent. 3 people get retrieved. PROBLEM 1: In the Month select, there are 3 ...
  3. Next n interface with cfloop and cfoutput group
    Hello does anyone have good examples on next n interfaces that work work well with cfoutput groups ? I have found most of the examples use <cfloop query startrow endrow> but <cfoutput query group> doesnt have the startrow or endrow attributes ?? Cheers JT
  4. problems with cfoutput and cfif statements
    I have hardcoded (bad-i know) a table for a May events calendar. Users can search for events by choosing one option at a time. If the search phrase matches I want to change the color of the cell and output the day number for the event date on the calendar. If the search ph...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: WattsboPosted on 2003-09-02 at 17:34:16ID: 9271107

I loop through my queries all the time, using the <cfoutput query> tag like you have...
At first glance, it looks to me like every iteration of the loop generates a page based on the first item in the list...When the query runs, it creates the set of records...as you go through looping through the query, although it takes one item at a time, it never deletes the item from the list, so returning the first item from the full query will always give the same result.
Are you expecting to get as output 1040 different pages? I mean, I might be mis-reading your code, but on the surface to me it looks like you're gonna run through your loop 1040 times, and generate a page each time...and this loop is run for each record that the query returns...Although I may be totally misreading it!!

Just for an example, here's a (simple) query of mine that I loop through, might help? Might not too ;-)

<CFQUERY name="GetGamestats" datasource="ruggers">
SELECT TA.TeamName AS TeamA, TB.TeamName AS TeamB, Game.GameID, Game.WhenGame,
         Game.TimeGame, Game.WinPick, Game.GameLocation, Game.TeamAScore, Game.TeamBScore,
         Game.TeamATries, Game.TeamBTries, Game.TeamARed, Game.TeamBRed, Game.TeamAYellow,
         Game.TeamBYellow, Game.TeamAID, Game.TeamBID
FROM Game INNER JOIN
     Team TA ON Game.TeamAID = TA.TeamID INNER JOIN
     Team TB ON Game.TeamBID = TB.TeamID
</CFQUERY>

<CFOUTPUT query="GetGamestats">
      #TeamA# VS #TeamB# In #GameLocation#, #dateformat(WhenGame, 'dd/mm/yyyy')# at #timeformat(TimeGame, 'HH:mm')#<br><br>
      <b><a href="./Teamstats.cfm?TeamID=#GetGamestats.TeamAID#" target="main"><font color="000000">
      #TeamA#</font></a> : #TeamAScore#</b><br>
      #TeamATries# tries scored<br>
      #TeamAYellow# yellow cards<br>
      #TeamARed# red cards<br><br>

      <b><a href="./Teamstats.cfm?TeamID=#GetGamestats.TeamBID#" target="main"><font color="000000">
      #TeamB#</font></a> : #TeamBScore#</b><br>
      #TeamBTries# tries scored<br>
      #TeamBYellow# yellow cards<br>
      #TeamBRed# red cards<br><br>
</CFOUTPUT>

Basically, all it does is goes and gets a whole lot of games from a database, then for each game that it gets, it outputs the information associated with that game; So, if it retrieves 3 games, the info/output after the <cfoutput query...> tag is generated individually for each game, and the <cfoutput query> tag knows that it's gotta loop through until it runs outta records...

What is your actual desired output from your code? What is the end result you're trying to generate?

 

by: hartPosted on 2003-09-02 at 21:58:39ID: 9271990

so basically u want to use the <cfoutput query inside the <cfloop,
i hope i understood u correctly :-)

i haven't checked this but just try and let e know

<!--- ======================================================== --->

<!-- Query of the products in our database --->
<CFQUERY name="products" datasource='nwchicagocdsco406'>
      SELECT Products.ProductName
      FROM Products
      GROUP BY Products.ProductName;
</CFQUERY>

<CFSET specialCharacters = " ()-">
<CFSET QueryEnd = products.recordcount>
<CFSET DrugName = "Vioxx">
<CFLOOP from="1" to="1040" index="i">
      <CFOUTPUT query="products">
            <CFSET NameLong = len(ListFirst(productname,specialCharacters))>
            <CFHTTP url="http://mysite.com/productinfo.jhtml?particularDrug=#ListFirst(productname,specialCharacters)#" resolveurl="no">
            <CFSET PTR = findnocase("Dosage Forms", cfhttp.FileContent, 1)>
            <CFSET END = len(cfhttp.FileContent)>
            <CFSET EndOfLoop = FindnoCase('<table width="100%"', cfhttp.FileContent, ptr)>#i#<BR><!-- PTR = #PTR#, EOL = #EndOfLoop#<BR>-->
            
            <CFLOOP condition="PTR LT EndOfLoop and ptr GT 0">
                  <CFSET hit = findnocase("#ListFirst(productname,specialCharacters)#", cfhttp.FileContent, PTR)><!--      HIT = #hit#<BR>-->
                  <CFIF hit GT 0>
                        <CFSET EndURL = findnocase('</td>', cfhttp.FileContent, hit)>
                        <CFSET EndURL = (EndURL)>
                        <CFSET HowLong = (EndURL - hit)>
                        <CFSET Links = mid(cfhttp.FileContent, (hit), (HowLong))><!--      DEBUG INFO: Links: #endURL#, #HowLong#, -->#Links#,
                        <CFSET hit2 = findnocase('000">', cfhttp.FileContent, PTR)>
                        <CFSET EndCount = findnocase("</td>", cfhttp.FileContent, hit2)>
                        <CFSET HowLongCount = (EndCount - hit2)>
                        <CFSET Count = mid(cfhttp.FileContent, hit2 + 5, HowLongCount)>#Count#,
                        <CFSET Hit3 = findnocase("$", cfhttp.FileContent, PTR)>
                        <CFSET EndPrice = FindnoCase("</td>", cfhttp.FileContent, hit3)>
                        <CFSET HowLongPrice = (EndPrice - Hit3)>
                        <CFSET Price = mid(cfhttp.FileContent, hit3, howlongprice)>#Price#<BR>
                        <CFSET PTR = hit + 1>
                  <CFELSE>
                        DUMPED THE LOOP!<BR>
                        <CFSET PTR = 0>
                  </CFIF>
            </CFLOOP>
            <CFSET Hit4 = findNoCase('Drug Manufacturer:</b>', cfhttp.filecontent, EndOfLoop)>
            <CFSET EndManufacturer = findnocase('<p><b>', cfhttp.FileContent, hit4)>
            <CFSET HowLongMan = (EndManufacturer - Hit4)>
            <CFSET Manufacturer = mid(cfhttp.FileContent, hit4, howlongman)>#Manufacturer#<BR>
            <CFSET Hit5 = findNoCase('Common Uses:</b>', cfhttp.FileContent, EndOFLoop)>
            <CFSET EndUses = FindNoCase('<p><b>', cfhttp.FileContent, Hit5)>
            <CFSET HowLongUses = (EndUses - Hit5)>
            <CFSET Uses = mid(cfhttp.FileContent, hit5, howlonguses)>#Uses#<BR>
            <CFSET i = (i + 1)>      
      </CFOUTPUT>
</CFLOOP>

<!--- ======================================================== --->

Regards
Hart

 

by: anandkpPosted on 2003-09-02 at 22:28:18ID: 9272089

well i dont understand why u have to use CFLOOP

u cld have just looped over the query

let me know if i have not understood ur requirement correctly !

K'Rgds
Anand

 

by: R_HosPosted on 2003-09-04 at 12:37:32ID: 9291009

Sorry for the confusion, but it made sence to me ... somewhere ;).  so basicly i have a number of products in my database which have coresponding pages on another site.  I want to pull those pages pull the important info and then compare it with my database.  (too many people doing too many diffrent things with no central reporting gets me in fixes like this.)  I appreciate all your help, I need to play with this for a bit and will get back to you guys.  Thanks so much again.

 

by: hartPosted on 2003-09-09 at 21:29:52ID: 9326133

Thanks for the A :-)

Regards
Hart

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...