FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » change of color on a field value basis in a table...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: change of color on a field value basis in a table... [message #180744 is a reply to message #180743] Sat, 16 March 2013 14:34 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
On 3/16/2013 9:16 AM, nag wrote:
> Hi,
> I am a newbie to php. Here I am trying to print the table
rows with different colors based on a value of a field.
But it is displaying the very first record in different
color and next is the other color until the date field changes.
>
> suppose:
>
> id dt
> xyz 05 (this is in #a99999 color)
> abc 05 (this is in #ffffff color)
> 123 05 (this is in #ffffff color)
> 324 06 (this is in #a99999 color)
> ccc 06 (this is in #ffffff color)
>
>
> but i need first three (with 05 date) in same color and next
records in other color alternatively.
>
> the following is my code:
>
>
> if($tmp!=$dt){$color="#a99999"; $tmp=$dt;}else{$color="#ffffff";}
>
> while($row = mysql_fetch_array( $result )) {
> $id=$row[1];
>
> $dt=substr($row[5],5,2);
>
> // Print out the contents of each row into a table
>
> $slno++;
> $tmp=$dt;
>
> if($tmp!=$dt){$color="#a99999"; $tmp=$dt;}else{$color="#ffffff";}
>
> echo "<tr bgcolor='$color'><td align='right'>";
> echo $slno;
> echo "</td><td><b>";
> echo $row[0];
> echo "</td><td align='center'>";
> ?>
> <a href="profile.php?id=<?php echo $idnum; ?>"><?php echo $idnum;?>
> </a>
> <?PHP
> echo "</td><td>";
> echo sprintf("%07d",$row[2]);
> echo "</td><td align='center'>";
> echo $row[3];
> echo "</td><td align='center'><b>";
> echo $row[4];
> echo "</td><td align='center'>";
> echo $row[5];
> echo "</td><tr>";
> }
> echo "</table>";
>
> thank you.
>

modestly confused: if I read what you wrote it seems you want
the 05 records to be #a99999 and
all other records to alternate between #fff and some other (as
yet unspecified) color ?

however:
$dt=substr($row[5],5,2);

// Print out the contents of each row into a table

$slno++;
$tmp=$dt; <<< this insures that $tmp will always = $dt

if($tmp!=$dt) { <<< so this will never be true
$color="#a99999";
$tmp=$dt;
}
else { <<< BTW, the brackets are not needed if it is a
single statement, but they are not wrong either
$color="#ffffff";
}

--
bill
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: script works fine now
Next Topic: why do I get a syntax error?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Dec 20 12:34:44 GMT 2024

Total time taken to generate the page: 0.03600 seconds