|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
alternating row colors
I want to alternate the color of the rows in a table that I am pulling off a database. I tried taking the variable
Code:
$i Code:
($i = 0....) Code:
$i % 2 = $result Code:
$result Any thoughts would help |
|
#3
|
|||
|
|||
|
RE: alternating row colors
Place this in your loop:
$bgcolor = ($bgcolor == "black" ? "white" : "black"); echo ('<td height="20" width="20%" valign="top" bgcolor="'.$bgcolor.'">You text here</font>'; |
|
#4
|
||||
|
||||
|
RE: alternating row colors
|
|
#5
|
||||
|
||||
|
RE: alternating row colors
|
|
#6
|
|||
|
|||
|
RE: alternating row colors
it would be like,
while(condition) { $bgcolor = ($bgcolor == "color1" ? "color2" : "color1"); echo '<td bgcolor="$bgcolor">'? } |
|
#7
|
|||
|
|||
|
RE: alternating row colors
I'm not sure I know how your code works siteworkspro.com. I don't think that I understand how the variables would switch.
|
|
#8
|
||||
|
||||
|
RE: alternating row colors
the other three above it all work fine...
|
|
#9
|
|||
|
|||
|
RE: alternating row colors
I can break it up for you:
$bgcolor = ($bgcolor == "color1" ? "color2" : "color1"); [var to contain value] = ([condition] ? [return this if condition is true] : [return this if condition is false]); |
|
#10
|
||||
|
||||
|
RE: alternating row colors
It was the while loop that through me because of the word condition. I started thinking that this was the condition being checked to flip the colors. I use the ternary operator (?
B |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > alternating row colors |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|