Solved

loop table cells

Posted on 2003-11-25
11
268 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
Comment Utility
<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
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
<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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 25

Accepted Solution

by:
James Rodgers earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
np...glad i could help

thanks for the points
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

10 Experts available now in Live!

Get 1:1 Help Now