Link to home
Create AccountLog in
Avatar of garyttu
garyttu

asked on

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....
Avatar of Scott Bennett
Scott Bennett
Flag of United States of America image

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>
ASKER CERTIFIED SOLUTION
Avatar of Scott Bennett
Scott Bennett
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Forced accept.

Computer101
EE Admin