Solved

loop table cells

Posted on 2003-11-25
11
270 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
  • 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable To Access a Web Domain From Our Network 16 84
Reverse Proxy Server 6 78
Problem to Eclipse 16 118
Using random iterations in password hashing.  Good or Bad? 4 76
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now