Solved

loop table cells

Posted on 2003-11-25
11
271 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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.
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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