Bir de böyle de deneyebilirsin...
<?php
$sql = "SELECT masaid, masaismi FROM masalar";
$result = $conn->query($sql);
    if ($result->num_rows > 0) {
            // output data of each row
    $Say = 0;
    $SutunSayisi = 3; //Hucre sayısını ayarla
    //$HucreGenisligi = number_format(100/$SutunSayisi); 
        while($row = $result->fetch_assoc()) {
            if (($Say % $SutunSayisi) == 0){
              echo '<tr>';
            }
        echo '
            <td>
                <button type="button" class="btn btn-block btn-primary btn-lg" data-toggle="modal"
                data-target="#exampleModal" data-whatever="'.$row["masaid"].'">'.$row["masaismi"].'</button>
            </td>';    
            $Say ++;
            if (($Say % $SutunSayisi) == 0){
              echo '</tr>';
            }
            
        }
    } else {
               echo "Masa yok";
    }
?>