Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with table

Status
Not open for further replies.

ivalum21

MIS
Jul 14, 2004
63
US
I have a table that has two columns, COMPANY NAME and CITY. The company can have locations in many different cities. I want to display the company name once, and the under CITY, have the cities listed...seperated by commas or something.

How can I do this??
 
Mind if I try a revision?

Code:
<!--- Query for displaying the institutions, city, and state. --->
<cfquery name="GetResults" datasource="#application.dsn#">
    SELECT cl_name, cl_city, cl_web_url
    FROM Corp_Location
    ORDER BY cl_name, cl_city
</cfquery>

<html>
<head>
    <title>IMBA</title>
</head>

<body>

<!--- Build table for results --->
<table align="center"
 cellspacing="2"
 cellpadding="2"
 border="8"
 frame="border">
 
 <th bgcolor="#FF8000">Company Name</th>
 <th bgcolor="#FF8000">City</th>
 <cfset colorRow = 1>
    <cfoutput query="GetResults" group="cl_name">
    
    <tr>
            <td bgcolor="<cfif colorRow MOD 2 EQ 0>##ff9900<cfelse>##FFFFFF</cfif>">#cl_name#</td>
        <td align="center" bgcolor="<cfif colorRow MOD 2 EQ 0>##ff9900<cfelse>##FFFFFF</cfif>">
       <cfset cityNum = 0>
       <cfset cityList = "">
       <cfoutput>
           [b]<cfset cityList = listAppend(cityList,cl_city)>[/b]
        </cfoutput>
        <cfset loopLen = listLen(#cityList#)>
        <cfloop from = "1" to="#loopLen#" index = "thisCity">
        #listGetAt(cityList, thisCity)#
        <cfif thisCity Mod 3 eq 0><br></cfif>
        </cfloop>
     </tr>
    <cfset colorRow = colorRow+1>
    </cfoutput>
    
</table>

The only changes were adding listappend.. ListAppend will do what the cfset you had did and also not have the trailing comma.. so then we could remove the cfif for the trailing comma.. which will get rid of the cfif being processed many times.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Code:
<cfset colorRow = 1>

Change that to:

Code:
<cfset colorRow = 1>
<cfset ArrColor=ListToArray("##ff9900,##ffffff")>

Code:
<td bgcolor="<cfif colorRow MOD 2 EQ 0>##ff9900<cfelse>##FFFFFF</cfif>">#cl_name#</td>
<td align="center" bgcolor="<cfif colorRow MOD 2 EQ 0>##ff9900<cfelse>##FFFFFF</cfif>">

and that can be changed to

Code:
<td bgcolor="#ArrColor[(colorRow mod 2) + 1]#">#cl_name#</td>
<td align="center" bgcolor="#ArrColor[(colorRow mod 2) + 1]#">

This is all a method I came up with a while back and I love the way it works.. as is the purpose of my prior post.. this kills CFIFs that don't need to be processed..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
3 minds are better than 1 there are always better ways to do something.

you'll still need to insert a coma and check for the last value because your code as you wrote it doesn't put a coma between the values when they're being output.



Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Agh, that's right..

Can't believe I missed that.. I guess I'm not up to par today..

But I know my array color trick is good.. :)

That's for kickstarting my brain Bomb..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
no worries. it happens to the best of us. :)

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Haha.. "That's" should have been "Thanks"

"That's" sounds rather spiteful.. haha.. didn't mean that at all..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I think we're staying within the terms on this one..



ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Alright alright alright!!

I get back from lunch and I have my answer waiting for me, you guys are awesome!

But....there is one more teensy thing that has me puzzled. First off, I'm using what bombboy posted above as my model because he has the commas being displayed correctly. My problem is, some companies have more than one location in a city. For example, ABC Company has 5 locations in Podunkville, therefore in my table, Podunkville is listed 5 times. Can I get it to display the city ONCE, if there are multiple locations in one city??
 
change...

Code:
<cfset cityList = listAppend(cityList,cl_city)>

to

Code:
<cfif not listfindnocase(citlist,cl_city)>]<cfset cityList = listAppend(cityList,cl_city)></cfif>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Ag.. I meant

Code:
<cfif not listfindnocase(cityList,cl_city)>]<cfset cityList = listAppend(cityList,cl_city)></cfif>

I'm doing horrid today.. I should quit typing and like go home or something ... agh..

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Beautiful...thank you very much bombboy and webmigit, you guys have been a huge help.

- ivalum21
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top