Change BGround Row Color depending on a Value in a Database field

S

Stuart

I have a Database of Staff and in the database is a field Called fldtype.
I have a table that show all the staff but it all start to blend in to a
mess just looking at same colours for everyone.

I have got the code to give alt row a different color and that helps but
what I really want is some code that will change the Bcolor and or Text color
depending on the field value contained in "fldType"

IE: If fldtype="Teacher" then Color red or if fldtpye="technician" then
color Green else if fldtype="Admin" then color orange.

Do you get what I mean.

I am new to this as I am a Netowrk man not a Web Coder but my School asked
if I could help out as site needs a major over haul.

Web editor being used is FP2000 and FP2003 at home.

Thanks
Sturt
 
T

Thomas A. Rowe

Can you paste the code that show how you are displaying the records?

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
S

Stuart

Here is code with the alt row color
<html>

<head>
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not
Edit.
FP_CharSet = "windows-1252"
FP_CodePage = 1252 %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>tblStaffList -- View</title>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>
<%
strOddColor = "bgcolor='#FFFFFF'"
strEvenColor = "bgcolor='#C0C0C0'"
intLineNum = 0
%>
<table width="100%" border="1">
<thead>
<tr>
<th ALIGN="LEFT"><b>Initials</b></th>
<th ALIGN="LEFT"><b>Surname</b></th>
<th ALIGN="LEFT"><b>Firstname</b></th>
<th ALIGN="LEFT"><b>Staff Type</b></th>
<th ALIGN="LEFT"><b>Department</b></th>
<th ALIGN="LEFT"><b>Room</b></th>
<th ALIGN="LEFT"><b>Other Info</b></th>
</tr>
</thead>
<tbody>
<!--webbot bot="DatabaseRegionStart"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-columntypes="3,202,202,202,202,202,202,202" s-dataconnection="Stafflist"
b-tableformat="TRUE" b-menuformat="FALSE" s-menuchoice="Intials"
s-menuvalue="Intials" b-tableborder="TRUE" b-tableexpand="TRUE"
b-tableheader="TRUE" b-listlabels="TRUE" b-listseparator="TRUE"
i-listformat="0" b-makeform="FALSE" s-recordsource="tblStaffList"
s-displaycolumns="Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-criteria s-order s-sql="SELECT * FROM tblStaffList" b-procedure="FALSE"
clientside suggestedext="asp" s-defaultfields s-norecordsfound="No records
returned." i-maxrecords="256" i-groupsize="0" botid="0"
u-dblib="../_fpclass/fpdblib.inc" u-dbrgn1="../_fpclass/fpdbrgn1.inc"
u-dbrgn2="../_fpclass/fpdbrgn2.inc" tag="TBODY" preview="<tr><td colspan=64
bgcolor="#FFFF00" width="100%"><font color="#000000">This is the start of a
Database Results region.</font></td></tr>" b-UseDotNET="FALSE" CurrentExt
sa-InputTypes b-DataGridFormat="FALSE" b-DGridAlternate="TRUE" sa-CritTypes
b-WasTableFormat="TRUE" startspan --><!--#include
file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database
Results component on this page is unable to display database content. The
page must have a filename ending in '.asp', and the web must be hosted on a
server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM tblStaffList"
fp_sDefault=""
fp_sNoRecords="<tr><td colspan=7 align=""LEFT"" width=""100%"">No records
returned.</td></tr>"
fp_sDataConn="Stafflist"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice="Intials"
fp_sMenuValue="Intials
fp_sColTypes="&ID=3&Intials=202&Surname=202&Firstname=202&fldType=202&Department=202&Room=202&OtherInfo=202&"
fp_iDisplayCols=7
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="../_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="52067" -->
<%
intLineNum = intLineNum + 1
If intLineNum Mod 2 = 0 Then
strLineColor = strEvenColor
Else
strLineColor = strOddColor
End If
%>
<tr <%=strLineColor%>>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="Intials" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE"
clientside b-MenuFormat preview="&lt;font
size="-1">&lt;&lt;</font>Intials<font size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"Intials")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="13821" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="Surname" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE"
clientside b-MenuFormat preview="<font size="-1">&lt;&lt;</font>Surname<font
size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"Surname")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="15149" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="Firstname" b-tableformat="TRUE" b-hashtml="FALSE"
b-makelink="FALSE" clientside b-MenuFormat preview="<font
size="-1">&lt;&lt;</font>Firstname<font size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"Firstname")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="18968" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="fldType" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE"
clientside b-MenuFormat preview="<font size="-1">&lt;&lt;</font>fldType<font
size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"fldType")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="15267" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="Department" b-tableformat="TRUE" b-hashtml="FALSE"
b-makelink="FALSE" clientside b-MenuFormat preview="<font
size="-1">&lt;&lt;</font>Department<font size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"Department")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="29735" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="Room" b-tableformat="TRUE" b-hashtml="FALSE" b-makelink="FALSE"
clientside b-MenuFormat preview="<font size="-1">&lt;&lt;</font>Room<font
size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"Room")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="5966" --></td>
<td>
<!--webbot bot="DatabaseResultColumn"
s-columnnames="ID,Intials,Surname,Firstname,fldType,Department,Room,OtherInfo"
s-column="OtherInfo" b-tableformat="TRUE" b-hashtml="FALSE"
b-makelink="FALSE" clientside b-MenuFormat preview="<font
size="-1">&lt;&lt;</font>OtherInfo<font size="-1">&gt;&gt;</font>" startspan
--><%=FP_FieldVal(fp_rs,"OtherInfo")%><!--webbot bot="DatabaseResultColumn"
endspan i-checksum="21234" --></td>
</tr>
<!--webbot bot="DatabaseRegionEnd" b-tableformat="TRUE"
b-menuformat="FALSE" u-dbrgn2="../_fpclass/fpdbrgn2.inc" i-groupsize="0"
clientside tag="TBODY" preview="<tr><td colspan=64 bgcolor="#FFFF00"
width="100%"><font color="#000000">This is the end of a Database Results
region.</font></td></tr>" startspan --><!--#include
file="../_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="56926" --></tbody>
</table>

<table width="100%" align=left id="table1">
<tr>
<td width="22%" align=right>
<table id="table2">
<tr>
<td>
Results Page
| <a href="editor/submission_form.asp" target="_top">Submission Form</a>
| <a href="editor/database_editor.asp" target="_top">Database Editor</a>
</td>
</tr>
</table>
</td>
</tr>
</table>


</body>

</html>
 
T

Thomas A. Rowe

I don't use the FP database components, but doing the following should work.

Replace the following:

<%
intLineNum = intLineNum + 1
If intLineNum Mod 2 = 0 Then
strLineColor = strEvenColor
Else
strLineColor = strOddColor
End If
%>

With:

<%
If FP_FieldVal(fp_rs,"fldType") = "Teacher" Then
strLineColor = "#FF0000" ' red
ElseIf FP_FieldVal(fp_rs,"fldType") = "Technician" Then
strLineColor = "#006600" ' green
ElseIf FP_FieldVal(fp_rs,"fldType") = "Admin" Then
strLineColor = "#FF9900" ' orange
Else
strLineColor = "#FFFFFF" ' white
End If
%>

Note the CaSe of Teacher, Technician, etc. in the database must exactly match the text in the equal
statement above.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
S

Stuart

Did not work all colours stayed the same.

How else can I display all the records and have this color option.

But must be easliy done as I will have to Show pupils in school how it was
done so they can mange it at a later date.
 
T

Thomas A. Rowe

Try changing what I wrote to:

<%
If fp_rs("fldType") = "Teacher" Then
strLineColor = "#FF0000" ' red
ElseIf fp_rs("fldType") = "Technician" Then
strLineColor = "#006600" ' green
ElseIf fp_rs("fldType") = "Admin" Then
strLineColor = "#FF9900" ' orange
Else
strLineColor = "#FFFFFF" ' white
End If
%>

And you did delete the following, correct?

<%
intLineNum = intLineNum + 1
If intLineNum Mod 2 = 0 Then
strLineColor = strEvenColor
Else
strLineColor = strOddColor
End If
%>

The only other way would be to not use the FP database component, and learn to hand code the
ASP/VBscript needed or you have to wait for someone that does use the FP database component to help
you.
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
Top