Tabelle immer nur mit 3 Spalten erstellen

Status
Dieses Thema wurde gelöst! Zur Lösung gehen…

EuroCent

Klappstuhl 2.0
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.

Beispiel:
PHP:
<?php
    $tableDraw = "";
    for($i = 1; $i <= 1; $i++) {
        $tableDraw .= '<table class="table table-hover table-bordered text-center" id="id_'.$i.'">'."\r\n";
            $tableDraw .= '<thead class="thead-light">'."\r\n";
                $tableDraw .= '<tr class="active">'."\r\n";
                    $tableDraw .= '<th style="width: 20% !important;"></th>'."\r\n";
                   
                    $tableDraw .= '<th style="width: 20% !important;">'."\r\n";
                        $tableDraw .= '<h3 title="[PROVIDERNAME]"><span class="[PROVIDERNAME]">[TAG]</span></h3>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm">[PRODUCTIONCATEGORY]</p>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm text-speed">[PRODUCTIONTAG]</p>'."\r\n";
                    $tableDraw .= '</th>'."\r\n";
                   
                    $tableDraw .= '<th style="width: 20% !important;">'."\r\n";
                        $tableDraw .= '<h3 title="[PROVIDERNAME]"><span class="[PROVIDERNAME]">[TAG]</span></h3>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm">[PRODUCTIONCATEGORY]</p>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm text-speed">[PRODUCTIONTAG]</p>'."\r\n";
                    $tableDraw .= '</th>'."\r\n";
                   
                    $tableDraw .= '<th style="width: 20% !important;">'."\r\n";
                        $tableDraw .= '<h3 title="[PROVIDERNAME]"><span class="[PROVIDERNAME]">[TAG]</span></h3>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm">[PRODUCTIONCATEGORY]</p>'."\r\n";
                        $tableDraw .= '<p class="text-muted text-sm text-speed">[PRODUCTIONTAG]</p>'."\r\n";
                    $tableDraw .= '</th>'."\r\n";
                   
                    $tableDraw .= '<th style="width: 20% !important;"></th>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
            $tableDraw .= '</thead>'."\r\n";
           
            $tableDraw .= '<tbody>'."\r\n";
                $tableDraw .= '<tr class="text-bold hide">'."\r\n";
                    $tableDraw .= '<td>Durschnittspreis pro Monat</td>'."\r\n";
                    $tableDraw .= '<td class="text-price text-underline">28.74 Euro</td>'."\r\n";
                    $tableDraw .= '<td class="text-price text-underline">31.37 Euro</td>'."\r\n";
                    $tableDraw .= '<td class="text-price text-underline">34.16 Euro</td>'."\r\n";
                    $tableDraw .= '<td>Durschnittspreis pro Monat</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                // TV SEKTION
                $tableDraw .= '<tr class="bg-dark text-white text-bold show_tv">'."\r\n";
                    $tableDraw .= '<td colspan="5">TV ([CONNECT_OPTIONS] Kabelanschluss) - Sektion</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Produkt</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Produkt</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv tv_connect hide">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Kabelanschluss</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_CONNECT_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_CONNECT_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_CONNECT_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Kabelanschluss</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Hardware (Endger&auml;t)</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Hardware (Endger&auml;t)</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Highlight (Aktion)</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Highlight (Aktion)</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv is_tv is_tv_entgelt">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Bereitstellungsentgelt</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_CABLE '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_DSL '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_UM '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Bereitstellungsentgelt</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_tv">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Komplettpreis</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_CABLE '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_DSL '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_UM '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Komplettpreis</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                // IP SEKTION
                $tableDraw .= '<tr class="bg-dark text-white text-bold show_ip">'."\r\n";
                    $tableDraw .= '<td colspan="5">Internet &amp; Phone - Sektion</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Produkt</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_NAME_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Produkt</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Internet Download</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_DOWNLOAD_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_DOWNLOAD_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_DOWNLOAD_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Internet Download</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Internet Upload</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_UPLOAD_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_UPLOAD_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_SPEED_UPLOAD_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Internet Upload</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Hardware (Endger&auml;t)</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HARDWARE_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Hardware (Endger&auml;t)</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Highlight (Aktion)</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_HIGHLIGHT_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Highlight (Aktion)</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip is_ip is_ip_entgelt">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Bereitstellungsentgelt</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_CABLE '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_DSL '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_UM '.$i.'] Euro</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Bereitstellungsentgelt</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
                $tableDraw .= '<tr class="show_ip">'."\r\n";
                    $tableDraw .= '<td class="text-bold">Komplettpreis</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_CABLE '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_DSL '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td>[PRODUCT_PRICE_IP_UM '.$i.']</td>'."\r\n";
                    $tableDraw .= '<td class="text-bold">Komplettpreis</td>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
               
            $tableDraw .= '</tbody>'."\r\n";
           
            $tableDraw .= '<tfoot>'."\r\n";
                $tableDraw .= '<tr class="bg-secondary">'."\r\n";
                    $tableDraw .= '<th colspan="5" class="foot"></th>'."\r\n";
                $tableDraw .= '</tr>'."\r\n";
            $tableDraw .= '</tfoot>'."\r\n";
           
        $tableDraw .= '</table>'."\r\n\r\n";
    }
    return $tableDraw;
?>

Alles das was in den Eckicken Klammern "[]" steht, wird per Datenbank dann befüllt bzw. ausgelesen.

Ich hatte dass zwar schon mal gemacht, aber das liegt Jahre zurück und irgendwie finde Ich da nicht den Ansatz :(

Mein Versuch:
PHP:
<?php
    $tableDraw = "";
    $count = 0;
    $counter = 0;
    $sql_prods = "SELECT * FROM [dbo].[vergleich_products] ORDER BY [created] DESC";
    $res_prods = $mainPage->getDataFromDb($sql_prods);
    while($row = sqlsrv_fetch_array($res_prods)) {
        //printf('<pre>%s</pre>', print_r($row, true));
        $count++;       
        if($counter < 1) {
            $tableDraw .= '<table class="table table-hover table-bordered text-center" id="id-'.$count.'">'."\r\n";
            $tableDraw .= '<thead class="thead-light">'."\r\n";
            $tableDraw .= '<tr class="active">'."\r\n";
            $tableDraw .= '<th style="width: 20% !important;"></th>'."\r\n";
            
            for($i = 0; $i < 3; $i++) {
                $tableDraw .= '<th style="width: 20% !important;">'."\r\n";
                    $tableDraw .= '<h3 title="[PROVIDERNAME]"><span class="[PROVIDERNAME]">[TAG]</span></h3>'."\r\n";
                    $tableDraw .= '<p class="text-muted text-sm">[PRODUCTIONCATEGORY]</p>'."\r\n";
                    $tableDraw .= '<p class="text-muted text-sm text-speed">[PRODUCTIONTAG]</p>'."\r\n";
                $tableDraw .= '</th>'."\r\n";
                
                $counter++;
            }
            
            $tableDraw .= '</table>'."\r\n\r\n";
        }
    }
?>
 
Status
Dieses Thema wurde gelöst! Zur Lösung gehen…