Jump to content

how can i get diffrent colors in a table cell from PHP or JS


naveenbj

Recommended Posts

Hello

 

Im not sure tht my title will give you much idea abt my problem.

So here is my explaination>>I have a table and in this table and the table data is coming from php code and this table can have more then 1 cell so what i want to achieve is to use two colors in this table cell

 

i kno it can be possible frm loops and i tried also but not gettting  :(

I hope this explanation will give enough idea abt my problem and if still any question abt my question thn let me kno

 

Thanks for you time and help

 

Regards,

Nj

Link to comment
Share on other sites

By "cell" do you mean "row". If so, your post makes sense. If not, then I don't know what you mean.

 

To alternate colors in a table you could do the following:

 

echo "<table>";

while ($row = mysql_fetch_assoc($result)} {
 $bgcolor = ($bgcolor=="#cecece")?"#696969":"#cecece";
 echo "<tr style=\"background-color:$bgcolor;\">";
 echo "<td>".$row['name']."</td>";
 echo "<td>".$row['phone']."</td>";
 echo "<tr>";
}

echo "</table>";

Link to comment
Share on other sites

By "cell" do you mean "row". If so, your post makes sense. If not, then I don't know what you mean.

 

To alternate colors in a table you could do the following:

 

echo "<table>";

while ($row = mysql_fetch_assoc($result)} {
 $bgcolor = ($bgcolor=="#cecece")?"#696969":"#cecece";
 echo "<tr style=\"background-color:$bgcolor;\">";
 echo "<td>".$row['name']."</td>";
 echo "<td>".$row['phone']."</td>";
 echo "<tr>";
}

echo "</table>";

 

Yes cell means row

Link to comment
Share on other sites

this is the code ehich im using

<table width="100%" border="0" CELLPADDING="3" CELLSPACING="1" CLASS="txt-norm" BGCOLOR="F4F7FD" ALIGN="LEFT"> 
<tr> <td width="17%" align="center" class="blueboldTxt"><DIV ALIGN="CENTER">Rank</DIV></td><td width="36%" align="center" class="blueboldTxt"><DIV ALIGN="CENTER">Username</DIV></td><td align="right"  class="blueboldTxt" width="47%"><DIV ALIGN="CENTER">Portfolio 
Value</DIV></td></tr> <?php 
if($count>7)
$totalrank=7;
else
$totalrank=$count;
for($i=0;$i<$totalrank;$i++)

{?> 
<tr><td align="center" WIDTH="17%" BGCOLOR="#FFFFFF"><FONT COLOR="18479B"><?php echo $i+1;?></FONT></td><td align="center" WIDTH="36%" BGCOLOR="#FFFFFF"><FONT COLOR="18479B"><?php $userid=$ar[0][$i];
echo $objUser->getUsernameByUserId($userid);?></FONT></td><td align="right" WIDTH="47%" BGCOLOR="#FFFFFF"><?php echo  number_format($ar[1][$i]);?></td></tr> 
<?php }?> <tr><td align="right" colspan="3"><a href="#" onClick='javascript: window.open("totalranking.php","OverallRanking","width=600,height=400,resizable=0,menubar=0,scrollbars=1");'><FONT COLOR="#FF6600">Overall 
Ranking</FONT></a></td></tr> </TABLE>

 

 

I need the colors one by one

for instance first row thn color=white and second row=black thn third row="white" and so on

so any clue abt this

 

 

Link to comment
Share on other sites

can any one help me for this

 

mjdamato already gave you the solution you need.  Don't use any background color for the td cells, use background color for the table rows.  Adjust his code to use your choice of alternate colors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.