Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equation to change every other two rows

What we want to do is change the background color of row in a table. The color will change for every other two rows.

Our id sequence is simple as follow:
id = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,.....etc.

1,2 rows -> black
3,4 rows -> white
5,6 rows -> black
7,8 rows -> white
9,10 rows -> black
11,12 rows -> white
13,14 rows -> black
15,16 rows -> white
17,18 rows -> black
etc....

if(id==1) || (id==2) class="black";
if(id==3) || (id==4) class="white";
if(id==5) || (id==6) class="black";
if(id==7) || (id==8) class="white";
if(id==9) || (id==10) class="black";
if(id==11) || (id==12) class="white";
etc.....

Depending on that id value, how can we change the color black or white?

Thanks a lot.

like image 921
Jonas T Avatar asked Jan 24 '26 07:01

Jonas T


1 Answers

bool white = ((rowId - 1) & 2) == 2;
like image 107
Mark H Avatar answered Jan 26 '26 20:01

Mark H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!