Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Changing $varCount & $row parameters in PHP

Featured Replies

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>';
        }


    ?>

 

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++;
    }
}
?>

 

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

 

  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.