Q:

Style Certain Table Rows from Database Query Set Data with CSS

I have a set of data in a MySQL database. I have a table created from these data using PHP loops. I want to style certain rows in certain ways. For example, the data fetched from the database are in groups of 2, 3, 4, 5 rows. There are a about 25 rows of data and I'd like to style each group a bit differently, e.g., add color to row sub heading...
I built this out and didn't quite take into consideration that this styling was necessary. The client wants this styling and now I'm trying to figure out how to make it.
Here is an image from Excel with the kind of thing I'm trying to accomplish:

I could just hand write the HTML and then style it but the code is much cleaner and tighter when using the PHP loops. Also, if I can figure this out, I could use this as a model and template for other scenarios where I need to style certain parts of a table from more data.
Here is the PHP snippet:
<table>
    <tr>
        <th>hd1</th>
        <th>hd2</th>
        <th>hd3</th>
    </tr>

    <?php

    $mysqli = <connect to db is fine>;

    $query = 'SELECT a, b, c from t1';

    if($stmt = mysqli_prepare($mysqli, $query)) {
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $a, $b, $c);

        while (mysqli_stmt_fetch($stmt)) {
            echo '<tr>';
            echo '<td>' . $a . '</td>';
            echo '<td>' . $b . '</td>';
            echo '<td>' . $c . '</td>'; 
            echo '</tr>';       
        }
    }

    ?>

</table>

A:

In this part of code add a class for your sub-headings : 
$subheadingsContent = array("a", "sub heading", "cell data");

while (mysqli_stmt_fetch($stmt)) {

    if(in_array($a, $subheadingsContent)) echo '<tr class="subheading">';

    echo '<td>' . $a . '</td>';
    echo '<td>' . $b . '</td>';
    echo '<td>' . $c . '</td>'; 
    echo '</tr>';       
}

And add class in your css file foreach element , for the first , the second , third .... :
 .subheading:nth-child(1){background-color:blue;}
 .subheading:nth-child(2){background-color:orange;}
 .subheading:nth-child(3){background-color:gray;}

