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


Groups > comp.lang.php > #8681

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: change of color on a field value basis in a table...
Date Sat, 16 Mar 2013 15:40:42 +0100
Organization A noiseless patient Spider
Lines 46
Message-ID <5144846A.9040102@arnowelzel.de> (permalink)
References <6dc42f7d-353e-4ac8-8821-b342bd74e3e1@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Info mx05.eternal-september.org; posting-host="94932bfd1af4237031c9a9a63d5b1416"; logging-data="5921"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19B9eCJwKX9qDUyV+Wx+xs5pIhGj+JVyYI="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4
In-Reply-To <6dc42f7d-353e-4ac8-8821-b342bd74e3e1@googlegroups.com>
Cancel-Lock sha1:01JR4rYyM2qFtZ8xiboNKbdG6oY=
Xref csiph.com comp.lang.php:8681

Show key headers only | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web