473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Change the bgcolor of a Dynamic <TD>

ak1dnar
1,584 Expert 1GB
Here in my PHP page there is a table. with five rows (based on my $str_list ). and there is bgcolor for each and every row, what i need to cange this bg color alternately. if the that means for row 1,3,5... and 2,4...there should be two different colors. can we do that by checking the $x value is odd or even.
[PHP]<html>
<body>
<table width="150" border="0" cellspacing="0" cellpadding="0">
<?php
$str_list = 'ABC;XYZ;PQR;KLM;HIJ';
$str = explode(';', $str_list);
for ($x=0; $x<count($str); $x++)
echo '
<tr height="17">
<td width="370" height="17" align="left" valign="top" bgcolor="#686666">'.$str[$x].'
</td>
</tr>' ;
?>
</table>
</body>
</html>[/PHP]
Mar 16 '07 #1
2 1952
devsusen
136 100+
Hi,

I think this code should work for u.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. $str_list = 'ABC;XYZ;PQR;KLM;HIJ';
  4.  
  5. $str = explode(';', $str_list);
  6.  
  7. for ($x=0; $x<count($str); $x++) 
  8.  
  9. $bgcolorcode = ($x%2 == 0)? "#686666" : "#eeeeee";
  10.  
  11. echo ' 
  12.  
  13. <tr height="17">
  14.  
  15. <td width="370" height="17" align="left" valign="top" bgcolor="'.$bgcolorcode.'">'.$str[$x].'
  16.  
  17. </td>
  18.  
  19. </tr>' ;
  20.  
  21. ?>
susen
Mar 17 '07 #2
ak1dnar
1,584 Expert 1GB
Thanks susen. :) i made it.
Mar 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Matt Adams | last post by:
I want to move the following <PRE> defintion to a css file: <TABLE><TR><TD><PRE>sample text</PRE></TD> <TD> not predefined font</TD></TR></TABLE> should be <TABLE><TR><TD class=aaa>sample...
1
by: Stan Brown | last post by:
In looking over my style sheet http://www.acad.sunytccc.edu/instruct/sbrown/screen.css I see that I have identical fonts and colors set on table and td elements. Is there any reason to do this,...
2
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a...
2
by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!--...
3
by: RC | last post by:
I have a very sime html table like <html><head><title>My Table</title> <style> input { margin: 0; padding: 0; border-width: 0; text-indet: 0; text-align: left } </style></head><body> <table...
3
by: Henry Johnson | last post by:
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically populate a table cell as follows (from C# code-behind)? I've tried using a Literal control in the...
5
by: mahesr | last post by:
I want to match some particular text between <tr>and </tr> or <td>and </td>.... in PHP. like below............ <table><tr> CATEGORY: <td><font face="Verdana" size="1" color="#A000A0"> Wedding...
4
George Lft
by: George Lft | last post by:
I'm new at building table. Mostly PHP programming . Now I can't seem to fix the size of my table row and column. Any idea? <h4>Two rows and three columns:</h4> <table border="1"> <tr> ...
7
by: Xiaoyan | last post by:
Hi,everyone: I have a problem now. I can't get the information between the <tr><td> and </td></tr>. for example: I use this regular expression can't get it, I don't know why....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.