[Solved] How to Not display empty rows?


You’re doing well, just apply a filtering function to each row you recieve:

// SO UPDATE THE QUERY TO ONLY PULL THAT SHOW'S DOGS
$query = "SELECT * FROM result
WHERE first IS NOT NULL";

$result = mysqli_query($connection, $query);

if (!$result) {

    trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($connection), E_USER_ERROR);

} else {

    // Fetch results into array
    $data = mysqli_fetch_all($result, MYSQLI_ASSOC);

    // If results array is not empty
    if ($data) {


        echo '<table class="table" border="0"></div>
        <tr>
          <td>
            <strong><?php echo $class_name ?></strong> - <h6>Entries: <?php echo $entries ?> Absentees: <?php echo $absentee ?></h6>
          </td>
          <td></td>
        </tr>';

        // Now let's walk through every record
        array_walk($data, function($dogRecord) {

            // Here we apply array_filter to each dog record, so that empty values (i.e. those evaluating to false) are filtered out
            $dogRecord = array_filter($dogRecord);


            // Now loop throw $dogRecord to build table

            $collation = [
                'DCC' => 'DCC',
                'RDCC' => 'RDCC',
                'BCC' => 'BCC',
                'RBCC' => 'RBCC',
                'BOB' => 'BOB',
                'BP' => 'BOB',
                'BJ' => 'BOB',
                '1ST' => 'first',
                '2ND' => 'second',
                '3RD' => 'third',
                'RES' => 'RES',
                'VHC' => 'RES'
            ];

            foreach ($dogRecord as $property => $value) {

                echo '<tr>
                    <td>'.$collation[$property].'</td>
                    <td>'.$value.'</td>
                </tr>';

            }

        });


        echo '</table>';
    }

}

Note that instead of simple foreach loop I’m using array_walk function. This is because since you extract variables for each record, you want undeclared (i.e. unoccupied) varables every time.

solved How to Not display empty rows?