Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8679 > unrolled thread

change of color on a field value basis in a table...

Started bynag <visitnag@gmail.com>
First post2013-03-16 06:16 -0700
Last post2013-03-17 06:31 -0400
Articles 5 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  change of color on a field value basis in a table... nag <visitnag@gmail.com> - 2013-03-16 06:16 -0700
    Re: change of color on a field value basis in a table... bill <william@TechServSys.com> - 2013-03-16 10:34 -0400
    Re: change of color on a field value basis in a table... Arno Welzel <usenet@arnowelzel.de> - 2013-03-16 15:40 +0100
    Re: change of color on a field value basis in a table... nag <visitnag@gmail.com> - 2013-03-16 09:17 -0700
      Re: change of color on a field value basis in a table... bill <william@TechServSys.com> - 2013-03-17 06:31 -0400

#8679 — change of color on a field value basis in a table...

Fromnag <visitnag@gmail.com>
Date2013-03-16 06:16 -0700
Subjectchange of color on a field value basis in a table...
Message-ID<6dc42f7d-353e-4ac8-8821-b342bd74e3e1@googlegroups.com>
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.

[toc] | [next] | [standalone]


#8680

Frombill <william@TechServSys.com>
Date2013-03-16 10:34 -0400
Message-ID<ki1vu1$a1g$3@speranza.aioe.org>
In reply to#8679
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

[toc] | [prev] | [next] | [standalone]


#8681

FromArno Welzel <usenet@arnowelzel.de>
Date2013-03-16 15:40 +0100
Message-ID<5144846A.9040102@arnowelzel.de>
In reply to#8679
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

[toc] | [prev] | [next] | [standalone]


#8684

Fromnag <visitnag@gmail.com>
Date2013-03-16 09:17 -0700
Message-ID<92b813a5-24fa-4c53-9551-74c755561c98@googlegroups.com>
In reply to#8679
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.

[toc] | [prev] | [next] | [standalone]


#8705

Frombill <william@TechServSys.com>
Date2013-03-17 06:31 -0400
Message-ID<ki462d$8dn$2@speranza.aioe.org>
In reply to#8684
On 3/16/2013 12:17 PM, nag wrote:
> 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.
>
AS pointed out in 2 earlier messages, as you assign $dt to $tmp 
before the compare, they will never differ.  I suspect you want 
to remove the first assignment (above the compare).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web