naveenbj Posted May 29, 2008 Share Posted May 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
prcollin Posted May 29, 2008 Share Posted May 29, 2008 do you have a set number of rows that are going to be displayed or different # for every display Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 29, 2008 Share Posted May 29, 2008 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>"; Quote Link to comment Share on other sites More sharing options...
naveenbj Posted May 29, 2008 Author Share Posted May 29, 2008 do you have a set number of rows that are going to be displayed or different # for every display no it can be 5 or 10:) Quote Link to comment Share on other sites More sharing options...
naveenbj Posted May 29, 2008 Author Share Posted May 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
naveenbj Posted May 29, 2008 Author Share Posted May 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
naveenbj Posted May 29, 2008 Author Share Posted May 29, 2008 can any one help me for this Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 29, 2008 Share Posted May 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.