使用php创建具有特定列数的表列

I have an array of data and want to display it on a table, but the columns that appear in the table according to the number of array data, how to make 12 column array default but the number remains on the database. suppose there are 2 data appear in the table but there are a number of columns 12...?

Models

function get_id($id) {
    $this->db->where('my_id', $id);
    $get_data = $this->db->get('mytable');
    if ($get_data->num_rows() > 0) {
        foreach ($get_data->result() as $data) {
            $my_result[] = $data;
        }
        return $my_result;
    }
}

Controllers

public function myControllers() {
    $id =  $this->uri->segment(4);
    $data=array('detail'    => $this->mymodels->get_id($id));
    $this->load->view('layout/wrapper', $data);
}

Views

<table>
    <thead> 
        <tr>
            <td>No</td>
            <td>ID</td>
            <td>Name</td>
            <td>Class</td>
        </tr>
    </thead>  
    <tbody> 
    <?php
        $no = 1;
        foreach ($detail as $row) {         
            echo '<tr>';
            echo '<td>'.$no.'</td>';
            echo '<td>'.$row->id.'</td>';
            echo '<td>'.$row->name.'</td>';
            echo '<td>'.$row->class.'</td>';
            echo '</tr>';

            $no++;
        }           
    ?>
    </tbody>      
</table>

I expected as this example

NO  | ID  | NAME | ClASS |
____|____ |______|_______|
 1  | 001 | Paul |    x  |
 2  |     |      |       |
 3  |     |      |       |
 4  |     |      |       |
to 12

If I'm understanding your question, you want to have a default of 12 rows in your table, even if only 2 rows are filled with data.

What about adding a while loop after your foreach loop that continues incrementing your counter and adding rows until your counter reaches 12?

while ($no <= 12) {
    echo '<tr>';
    echo '<td>'.$no.'</td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '</tr>';
    $no++;
}