Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

loop table cells

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
phillystyle123
Asked:
phillystyle123
  • 7
  • 3
1 Solution
 
PE_CF_DEVCommented:
<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
 
James RodgersWeb Applications DeveloperCommented:
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
 
James RodgersWeb Applications DeveloperCommented:
<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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
phillystyle123Author Commented:
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
 
James RodgersWeb Applications DeveloperCommented:
<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
 
James RodgersWeb Applications DeveloperCommented:
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
 
phillystyle123Author Commented:
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
 
James RodgersWeb Applications DeveloperCommented:
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
 
James RodgersWeb Applications DeveloperCommented:
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
 
phillystyle123Author Commented:
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
 
James RodgersWeb Applications DeveloperCommented:
np...glad i could help

thanks for the points
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now