在修复html表上显示php数组而不影响行数

I am still in the process of learning PHP and would like to seek for your assistance regarding my concern. I already know how to display an array into an html table which i usually do with my forms. Then suddenly i came into this issue wherein there should be a fix table with a fix number of rows (lets say about 5 rows).

Now if i would display information coming from a specific user and that user only has 2 rows of data from mysql then i will only have 2 rows displayed on my html table.

What happens:

*****************
** A ** B ** C **
*****************
** 1 ** 2 ** 3 **
*****************
** 4 ** 5 ** 6 **
*****************

What i want as an output:

*****************
** A ** B ** C **
*****************
** 1 ** 2 ** 3 **
*****************
** 4 ** 5 ** 6 **
*****************
**   **   **   **
*****************
**   **   **   **
*****************

Is there a neat way to code this. Your idea is already a big help; I am not asking for codes but you can somehow guide me on what i can do here in order to achieve the output i want.

Thanks.

You could maintain a second counter with your fixed number calculations. In pseudo-code, it might look like this:

$rowCount = 0;
while (getNextDataRow()) {
    printDataRow();
    $rowCount++;
}
while ($rowCount <= 5) {
    printEmptyRow();
    $rowCount++;
}

Note that this would add empty rows when needed, but it wouldn't constrain the number of rows if the data contains more than 5. It's up to you what to do in that case. The data query could have a LIMIT to prevent that from happening, the first while loop could have a check for $rowCount == 5 and exit the loop, etc.

Use a for loop with an if statement. Something like this:

$myData = array(
    array('A', 'B', 'C'),
    array('1', '2', '3'),
    array('4', '5', '6')
);
for ($i = 0; $i < 5; $i++)
{
    echo '<tr>';
    if (isset($myData[$i]))
    {
        echo '<td>'.$myData[$i][0].'</td>';
        echo '<td>'.$myData[$i][1].'</td>';
        echo '<td>'.$myData[$i][2].'</td>';
    }
    else
    {
        echo '<td>&nbsp;</td>';
        echo '<td>&nbsp;</td>';
        echo '<td>&nbsp;</td>';
    }
    echo '</tr>';
}

You can fill your array with empty strings till its count is 5:

$array = array(array(1,2,3),array(4,5,6));
for($i=0, $add = 5-count($array);$i<$add;$i++){
    $array[]=array('','','');
}
var_dump($array);

Output:

array (size=5)
  0 => 
    array (size=3)
      0 => int 1
      1 => int 2
      2 => int 3
  1 => 
    array (size=3)
      0 => int 4
      1 => int 5
      2 => int 6
  2 => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)
  3 => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)
  4 => 
    array (size=3)
      0 => string '' (length=0)
      1 => string '' (length=0)
      2 => string '' (length=0)