Solved

loop table cells

Posted on 2003-11-25
11
277 Views
Last Modified: 2013-12-24
i'm using the following code to generate one image and an artist's name next to the image. i need to make this data loop across table cells so i have like 2 or 3 columns and say 5 rows INSTEAD of how it currently shows which is 1 column, repeat rows.

here's the URL:
http://www.ikonltd.com/artists/index.cfm

here's my code:

<table width="40%" border="0" cellspacing="2" cellpadding="2"><tr><td valign="top" colspan="5"><h1>Artists</h1></td></tr>
                        <cfquery name="Artists" datasource="Ikonltd">
SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
FROM Artists, Artwork
Where Artists.ArtistID=Artwork.ArtistID and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>

<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
   
<tr>
     <cfloop  query="getArtistImage">
                          <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
      
   
       <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>

  </tr>
  <tr>
                        <td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
                      </tr></cfoutput>
</table>
0
Comment
Question by:phillystyle123
[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
  • 7
  • 3
11 Comments
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9818988
<cfquery name="Artists" datasource="Ikonltd">
      SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
      FROM Artists INNER JOIN Artwork ON Artists.ArtistID=Artwork.ArtistID<!--- Changed --->
      Where Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
      GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>
<cfset columns="4"><!--- Added --->
<table width="40%" border="0" cellspacing="2" cellpadding="2"><tr><td valign="top" colspan="5"><h1>Artists</h1></td></tr>
<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>  
<cfif columns EQ 4><tr></cfif><!--- Added --->
      <cfloop  query="getArtistImage">
      <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
      </cfloop>
      <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<cfif columns eq 0></tr><cfset columns=4><cfelse><cfset columns=columns-1></cfif><!--- Added --->
<tr>
      <td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
</tr>
</cfoutput>
</table>

This may need a little work you get it to fit your exact needs but the idea here is put a counter in (columns) when it reaches a specific number it puts in the <tr> tags.

Also I think the outputs might be able to get changed around to make it run better but thats a diferent subject....
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9819206
you can also use the currentRow variable of the output query rather than creating a new variable

<cfif  not query.currentRow mod 4>
</tr><tr>
</cfif>
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9819240
<table width="40%" border="0" cellspacing="2" cellpadding="2"><tr><td valign="top" colspan="5"><h1>Artists</h1></td></tr>
                    <cfquery name="Artists" datasource="Ikonltd">
SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
FROM Artists, Artwork
Where Artists.ArtistID=Artwork.ArtistID and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>


<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
   
<tr>
<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</cfoutput>
</tr>
</table>
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:phillystyle123
ID: 9819576
thanks for the replies!  Jester_48, I think i ended up using your code, although i tried both and both rendered the same result (you can see http://www.ikonltd.com/artists/indextd.cfm)

i tried playing around with it, changing the max rows - it's def. got something to do with the loop factor.

<cfquery name="Artists" datasource="Ikonltd">
SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
FROM Artists, Artwork
Where Artists.ArtistID=Artwork.ArtistID and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>


<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
   
<tr>
<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</tr></cfoutput>

</table>



0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9819763
<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
   
<tr>  <---move this outside the loop



<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</tr></cfoutput>

</table>

-----------------------------------------------------------------


<tr>
<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
   

<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</tr></cfoutput>

</table>

0
 
LVL 25

Accepted Solution

by:
James Rodgers earned 100 total points
ID: 9819861
this one too

<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</tr>   <--- place outside cfoutput block

</cfoutput>

</table>

---------------------------------


<cfquery name="Artists" datasource="Ikonltd">
SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
FROM Artists, Artwork
Where Artists.ArtistID=Artwork.ArtistID and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>

<tr>
<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
<cfloop  query="getArtistImage">
     <td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
<cfif not Artists.currentRow mod 4>
</tr>
<tr>
</cfif>
</cfoutput>
</tr>
</table>
0
 

Author Comment

by:phillystyle123
ID: 9820379
Jester_48 - the last one worked!!!!!  

http://ikonltd.com/artists/indextd.cfm

can't wait to figure out what you did and apply it to some other pages. one thing though    - currently it's last name asc by column - is there a way to make the lastname asc from left to right?

eg:

a   e  i
b   f   j
c   g
d   h
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9820472
that would mean redesigning the output to have each group vertically in a table and the number of rows in the table would need to be dynamically determined at runtime in order to have it applied properly, almost eveything you have so far would have to be rewritten
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9820570
try this... might need som tweaking, i haven't looked it over completely... time to go home

<cfquery name="Artists" datasource="Ikonltd">
SELECT Artists.FirstName, Artists.LastName, Artists.ArtistID, Artwork.ArtistPage, Artwork.sm
FROM Artists, Artwork
Where Artists.ArtistID=Artwork.ArtistID and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
GROUP BY Artists.LastName ORDER BY Artists.LastName Asc
</cfquery>

<tr>
<td>
<table>
<cfset iNumRows=0>
<cfoutput query="Artists">
    <cfquery name="getArtistImage" datasource="Ikonltd" maxrows="1">
           SELECT Artwork.sm, AutoArtID
           FROM  Artwork
           Where ArtistID = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="#Artists.ArtistID#"> and Artwork.ArtistPage = <CFQUERYPARAM CFSQLTYPE="cf_sql_numeric" VALUE="1">
   </cfquery>
   <tr>
   <cfset sFname = Artists.FirstName>
   <cfset sLname = Artists.LastName>
   <cfset nArtistID = Artists.ArtistID>
   <cfset nAutoArtID = getArtistImage.AutoArtID>
<cfloop  query="getArtistImage">
     </tr><td width="5%" valign="top"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><img src="../images/sm/#sm#" border="0"></a></td>
</cfloop>
     <td width="88%"><p class="artistname"><a href="details.cfm?ArtistID=#nArtistID#&AutoArtID=#nAutoArtID#"><b>#sFname#&nbsp;#sLname#</b></a></p></td>
<td valign="top"><img src="../images/spacer.gif" width="20" height="3"></td>
</tr>
<cfif iNumRows = Artists.recordCount /4 or (Artists.currentRow=Artists.recordCount)>
      <cfset iNumRows =0>
      
      </table>
      <td>
      <table>

</cfif>
<cfif not Artists.currentRow mod 4>

</table>
</td>
</tr>
<tr>
<td>
</cfif>
<cfset iNumRows=iNumRows+1>
</cfoutput>
</td>
</tr>
</table>
0
 

Author Comment

by:phillystyle123
ID: 9820740
thanks man - don't even need it they're fine the with the the asc the way it is - thanks for your help!!!!!!!1
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9824266
np...glad i could help

thanks for the points
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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