• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

Highlighting changes between table rows

Let's say I have 2 rows in a SQL table. The second is a copy of the first only one or two columns are now changed.  Basically I have created a revision of row one but want to keep the original row as well.

I output this new row of data to an CFM page-  only I want to highlight the changes to the row by highlighting the output in red.  Is there anyway to do this on the fly for each cfoutput?  Basically I don't want to have to do a CFIF for EVERY output to compare column data of each row and change the text color inside the cfif if it has changed (or change the CSS style).  Not sure if this is the only way but it sure seems cumbersome and seems like it would be unnecessarily long code....
0
garyttu
Asked:
garyttu
  • 2
1 Solution
 
Scott BennettCommented:
you will have to check each value but you can do a short cut by looping through a list of the column names you want to check like this (untested):


<cfset columnlist = "column1,column2,column3">
<cfloop query="query1">
<cfset bgcolor="white">
<cfloop list="columnlist" index="i">
<cfif query1[i] neq query2[i]>
      <cfset bgcolor = "red">
</cfif>
</cfloop>
<tr bgcolor="#bgcolor#">
      <cfloop list="columnlist" index="i">
      <td>#query1[i]#</td>
      </cfloop>
</tr>
</cfloop>
0
 
Scott BennettCommented:
sorry read your question a little closer and it looks like you need something more like:

<cfset columnlist = "column1,column2,column3">
<cfquery name="GetRows" datasource="DSN" maxrows="2">
SELECT #columnlist#
FROM MyTable
</cfquery>
<cfoutput>
<table>
      <tr>
            <td>Column Name</td>
            <td>Row 1 Value</td>
            <td>Row 2 Value</td>
      </tr>

<cfloop query="GetRows">
<cfset bgcolor="white">
<cfloop list="columnlist" index="i">
<tr>
      
      <cfif GetRows[i][1] neq GetRows[i][2]>
            <cfset bgcolor = "red">
      </cfif>
      <td bgcolor="#bgcolor#">#i#</td>
      <td bgcolor="#bgcolor#">#GetRows[i][1]#</td>
      <td bgcolor="#bgcolor#">#GetRows[i][2]#</td>
</tr>
</cfloop>
</cfloop>
</table>
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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