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 :: Unread Messages :: Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
change of color on a field value basis in a table... [message #180743] Sat, 16 March 2013 09:16 Go to next message
Nagaraju Kachapuram is currently offline  Nagaraju Kachapuram
Messages: 14
Registered: February 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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.
Message by bill is ignored  [reveal message]  [reveal all messages by bill]  [stop ignoring this user] Go to previous messageGo to next message
Re: change of color on a field value basis in a table... [message #180745 is a reply to message #180743] Sat, 16 March 2013 10:40 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
nag, 2013-03-16 14:16:

> 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;

Why this? You want to check, if the new date differs. So why do you
assign $dt to $tmp, before you compare it here (and assign the different
value to $tmp then again)?

> if($tmp!=$dt){$color="#a99999"; $tmp=$dt;}else{$color="#ffffff";}
> echo "<tr bgcolor='$color'><td align='right'>";




--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: change of color on a field value basis in a table... [message #180748 is a reply to message #180743] Sat, 16 March 2013 12:17 Go to previous messageGo to next message
Nagaraju Kachapuram is currently offline  Nagaraju Kachapuram
Messages: 14
Registered: February 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
On Saturday, 16 March 2013 18:46:53 UTC+5:30, 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.

Here in my data the date differs in a month. So I want to display same month records in one color. Maximum i will have three different months records. Thats the reason i am checking $dt (month tag from the date) is same from the previous date.


the code :

if($tmp!=$dt){
$color="#a99999";
$tmp=$dt;

}else{
$color="#ffffff";
}

is not working.
Message by bill is ignored  [reveal message]  [reveal all messages by bill]  [stop ignoring this user] Go to previous message
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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: Tue Mar 18 01:03:05 EDT 2025

Total time taken to generate the page: 0.04066 seconds