如果我的值少于8个,则将MySql数据拆分为3列

I want to display some data split into 3 columns. If I have more than eight values​​, then everything is working properly, but if I have less than eight values I get: Notice: Undefined offset:

How can I fix that problem?

 echo '<table><tr>';    
    for ($i=0;$i < count($audio_fileexts) / 3; $i++) {  
        for ($j = 0; $j < 3; $j++){ 
            echo $audio_fileexts[ $i + $j * 3]; 
        }               
        echo '</tr><tr>';           
    }           
echo '</tr></table>';
echo '<table>';    

for ($i = 0; $i < count($audio_fileexts); $i++) {
    if ($i % 3 == 0) {
        if ($i > 0) {
            echo '</tr>';
        }
        echo '<tr>';
    }

    echo '<td>' . $audio_fileexts[$i] . '</td>';
}

if ($i % 3 > 0) {
    while ($i++ % 3 > 0) {
        echo '<td></td>';
    }
    echo '</tr>';
}

echo '</table>';