This topic is locked

ListOnLoad event help

9/13/2006 2:24:44 PM
PHPRunner General questions
M
markdorminy author

I need to be able to vary a row's background color depending on the value of a field on that row. Specifically, I need to be able to make the color red if the due date is < 3 days away. The date math is easy, but I can't figure out how to change the row's background color using the ListOnLoad event.
Any suggestions?
Thanks!

MD

D
drh 9/13/2006

Hi dorm,

finally I get a chance to help. This forum is really very good.
I needed to display records in the list page with different color backgrounds based on how long ago the record was entered.
I didn't do it using the ListOnLoad event. Maybe that is the correct way, but I did it this way.
In my ...list.php file I located this line ......... function loopRs($rsData,$nPageSize) and edited the function completely. Here is the edited function loopRs:
// display table with results

function loopRs($rsData,$nPageSize)

{

global $mypage,$strKeyField,$strKeyField2,$strKeyField3,$ownerid,$fieldlist,$LookupSQL,$conn,$nColumns,$strTableName

,$thumbnail_fields,$thumbnail_prefixes,$thumbnail_maxsize;

global $ColumnsCount;

// Pagination:

$iShadeTheDetail=0;

$iNumberOfRows = 0;

$nDelete=1;

$totals=array();
if($rsData)

{
$data=db_fetch_array($rsData);
while($data && $iNumberOfRows<$nPageSize)

{

$dateEntered = $data["Date_Entered"];

$yrEntered = substr($dateEntered,0,4);

$monEntered = substr($dateEntered,5,2);

$dayEntered = substr($dateEntered,8,2);

$jdEntered = GregorianToJD($monEntered, $dayEntered, $yrEntered);
$today = date('Y-m-d');

$yrToday = substr($today,0,4);

$monToday = substr($today,5,2);

$dayToday = substr($today,8,2);

$jdToday = GregorianToJD($monToday, $dayToday, $yrToday);
$numdays = ($jdToday - $jdEntered);
$sShadeClass = "class=shadeW"; // default color white

// To insure that every other one is shaded

if((($data["Account_Status"]) == "P") && ($numdays <= "15"))

{

$sShadeClass = "class=shadeR";

//$iShadeTheDetail = 1;

}

if((($data["Account_Status"]) == "P") && ($numdays >= "16"))

{

$sShadeClass = "class=shadeY";

//$iShadeTheDetail = 1;

}

if(($data["AccountStatus"]) == "N")

{

$sShadeClass = "class=shadeG";

//$iShadeTheDetail = 0;

}

?>
<tr valign=top
<?php echo $sShadeClass;?> (<?php echo $iNumberOfRows/$ColumnsCount;?>, 0);" id="tr
<?php echo $iNum

berOfRows/$ColumnsCount;?>" >
<?php for($i=0;$i<$ColumnsCount;$i++)

{ ?>
Okay, now one more file to edit errrrr enhance as I prefer to call it. ./include/style.css
I looked for .shade and added the following code to change to the colors I wanted. Note that I also changed the color of the type so that the data could be easily read.
.shade

{

COLOR: #333333;

BACKGROUND-COLOR: #DFE6EF;

}

.shadeW

{

COLOR: #000000; / was 333333 /

BACKGROUND-COLOR: #CCCCCC; /#FFFFFF;/

}

.shadeR

{

COLOR: #333333;

BACKGROUND-COLOR: #FF9999; /#c64444; #FF0000;/

}

.shadeG

{

COLOR: #333333;

BACKGROUND-COLOR: #99CC99; /#66cc99; #33FF00;/

}

.shadeY

{

COLOR: #333333;

BACKGROUND-COLOR: #FFFF99; /#dde769; #FFFF00;/

}
All this assumes that you don't want to change shades when "mousing" over the records. I use four different colors, but you could have as many colors as you want.
I don't profess to be an expert at php or style sheets, but this did the trick for me. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=11048&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />
Dave

M
markdorminy author 9/14/2006

Well, I don't know if it's "right" or not, but it works and that makes it "right" as far as I'm concerned. Thank you for your help! It's just what I needed!
MD

M
markdorminy author 10/30/2006

This was great in 3.0, but I haven't been able to find how to do it in 3.1. Anyone tried yet?