December 20, 20169 yr Hi, I'd like to creat a sorting order with a $varCount like: 1 1 2 2 3 3 and alternating row colors that will print: pink pink yellow yellow pink pink Here is the kind of coding I'm using that works fine for sequential numbering and odd/even row colors. I appreciate anyone who can help me change these parameters, as I have tried every combination I could think of. Thanks! <?php $row = 0; $varCount = 0; foreach($records as $record) { $varCount = $varCount + 1; if($row % 2 == 0) { echo '<tr class="alt_row_color">'; } else { '<tr>'; } ?>
December 20, 20169 yr Try this: <?php $row=0; $bgcolor = 1; foreach($records as $record){ $row++; if($bgcolor == 3){ $bgcolor = 1; } if($bgcolor == 1){ echo '<tr class="alt_row_color">';// ...etc } else { echo '<tr>';// ...etc } if($row % 2 == 0){ $bgcolor++; } } ?>
December 20, 20169 yr Alternating rows is fairly simple - this divides by two and returns the remainder - 0 for an even row, 1 for an odd row if($row % 2 == 0) For double rows, I would probably divide by four, and check the remainder instead - remainders of 1 and 2 are one row colour, 3 and 0 (as exactly divisible by 4) would get the other row colour
December 21, 20169 yr Author Thanks Doughemi and Webko, I tried both techniques and did not get the results I'm looking for. I don't know if it's possible to do. I'm ranking tennis doubles players, here's a link. http://ssvtennis.com/include-sd-ssvcuprankings.php
Create an account or sign in to comment