• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

another loop question

Participant ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

Can anyone tell me what I'm doing wrong? I'm trying to loop through my recordcount of a query to create multiple <divs> that another piece of code will rotate. That seems to be working fine, but I can't figure out how to get different info from my query statment into each one of those <divs> It picks up the first record in my query and repeats it. Here is the code I'm using.

<cfquery name="qfeatured" datasource="mydb">
SELECT * FROM Places WHERE featured = 'yes' ORDER BY establishment
</cfquery>


<cfoutput query="qfeatured">
<cfif establishment_type EQ "Restaurant" OR establishment_type EQ "Bar/Restaurant">


<cfloop from="0" to="#qfeatured.recordcount#" index="i">
<div id="dropmsg#i#" class="dropcontent" subject="">

<table cellspacing="3" cellpadding="3" width="100%">
<tr>
<td bgcolor="##3D5285" valign="top">#i# - #establishment#</td>
</tr>
</table>

</div>
</cfloop>
</cfif>
</cfoutput>

These returns the results as:

0 - My Establishment Name
1 - My Establishment Name
2 - My Establishment Name

What I am trying to make it do is:

0 - My First Establishment Name
1 - My Second Establishment Name
2 - My Third Establishment Name


TOPICS
Advanced techniques

Views

297

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

<td bgcolor="##3D5285" valign="top">#i# - #qfeatured.establishment[ i ]#</td>

(note the spaces in [ i ] shouldn't be there... just trying to prevent the italics from kicking in) 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

The cfoutput itself loops. Is the following perhaps what you wanted

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

Let's look at this line:
<cfloop from="0" to="#qfeatured.recordcount#" index="i">

Somehow I see this giving you names of establishments that are not bars or restaurants.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

LATEST
You were right Dan, that was only giving me numbers....which didn't help at all. BKBK's code did the trick. I think at one point I tried that, turns out the <cfif establishment_type EQ "Restaurant" OR establishment_type EQ "Bar/Restaurant"> was causing it to skip some numbers in it's count.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation