Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: bill Newsgroups: comp.lang.php Subject: Re: change of color on a field value basis in a table... Date: Sun, 17 Mar 2013 06:31:42 -0400 Organization: Aioe.org NNTP Server Lines: 143 Message-ID: References: <6dc42f7d-353e-4ac8-8821-b342bd74e3e1@googlegroups.com> <92b813a5-24fa-4c53-9551-74c755561c98@googlegroups.com> NNTP-Posting-Host: 3qER3ivYp3VzEuZD7C/pcg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.php:8705 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 ""; >> >> echo $slno; >> >> echo ""; >> >> echo $row[0]; >> >> echo ""; >> >> ?> >> >> >> >> >> >> > >> echo ""; >> >> echo sprintf("%07d",$row[2]); >> >> echo ""; >> >> echo $row[3]; >> >> echo ""; >> >> echo $row[4]; >> >> echo ""; >> >> echo $row[5]; >> >> echo ""; >> >> } >> >> echo ""; >> >> >> >> 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).