Tabelle immer nur mit 3 Spalten erstellen

Hallo zusammen, aktuell stehe Ich auf dem Schlauch. Ich möchte eine Tabelle erstellen, die nur 3 Spalten hat, Zeilen sind dabei egal. Wenn die 3 Spalten voll sind, dann muss eine neue Tabelle erstellt und im selbigen Aufbau geschrieben werden. Die Daten kommen dann aus der Datenbank und werden entsprechend befüllt.

Der hier verwendete Code

<style> table{ margin:20px auto; border:1px solid black; width:80vw; border-collapse: collapse; } td{ border:1px solid black; } h5{ text-align:center; } th{ border:1px solid black; background:lightgrey; } </style> <script> var tableDraw = ""; tabellen=0; all=0; mengeausgabe=30; for(count=0;count<mengeausgabe;count++){ if(count%3==0) { tabellen++; tableDraw += '<h5>Tabelle '+tabellen+'</h5><table id="table'+tabellen+'"><thead class="thead-light">'; tableDraw += '<tr class="active">' ; tableDraw += '<th>Id</th><th>links</th><th>User</th><th>telefon</th></tr>'; for(i = 0; i < 3; i++) { all++; tableDraw += '<tr>' ; tableDraw += '<td>Ta'+tabellen+'li'+all+'</td>' ; tableDraw += '<td>link '+all+'</td>' ; tableDraw += '<td>user '+all+'</td>' ; tableDraw += '<td>tele '+all+'</td>' ; tableDraw += '</tr>' ; } tableDraw += '</tbody></table>' ; } } document.write(tableDraw); </script>