1 * 1 - Tabelle, strukturieren und "Zeilenüberschriften" hinzufügen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 1 * 1 - Tabelle, strukturieren und "Zeilenüberschriften" hinzufügen

    Hallo zusammen,

    stehe momentan etwas auf dem Schlauch, ich habe über folgendes Script eine 1 * 1 - Tabelle erzeugt. Nun möchte ich die jeweiligen Zeilen noch mit einer Überschrift versehen und bin mir unschlüssig, wo ich das bestenfalls platziere. Ich denke dass aus diesem Grund die Tabelle ein wenig unförmig geworden ist.

    PHP Code:
    <!DOCTYPE html>
    <html lang="de">
    <head>
    <meta charset="utf-8" />
    <title>E1_1mal1</title>
    </head>
        <body>
        <h1>Das kleine 1 mal 1</h1>
            <table>
                <thead>
        <?php
                    
    echo "<th>*</th>";
        
                    for (
    $i 0$i <= 10$i++) { 
                        echo 
    "<th>";
                        echo 
    $i;
                                                                      }
                    
    ?>
           </thead> 
                <tbody>
        <?php
                 
                
    for ($i 1$i <= 10$i++)
    {
    echo 
    "";
    for (
    $j 1$j <= 10$j++)
    {
    echo 
    "<td>"
    echo (
    $i $j);
    echo 
    "</td>";
    }
    echo 
    "</tr>";
    }
                    
    ?>
                    </tbody>
            </table>
        </body>
    </html>


    Sicherlich eine Banalität, für mich mit wenigen Tagen Erfahrungen mit php dennoch eine Herausforderung.

    Vielen Dank!

    Kalle

  • #2
    PHP Code:
    <?php

    $max_multiplier 
    10;

    ?>

    <style>
        td, th {
            width: 3ex;
            text-align: right;
        }
    </style>

    <table>
        <tr>
            <th></th>
            <?php foreach (range(1$max_multiplier) as $x): ?>
                <th><?= $x ?></th>
            <?php endforeach; ?>
        </tr>
        <?php foreach (range(1$max_multiplier) as $y): ?>
            <tr>
                <th><?= $y ?></th>
                <?php foreach (range(1$max_multiplier) as $x): ?>
                    <td><?= $x $y ?></td>
                <?php endforeach; ?>
            </tr>
        <?php endforeach; ?>
    </table>

    Comment


    • #3
      Originally posted by h3ll View Post
      PHP Code:
      <?php

      $max_multiplier 
      10;

      ?>

      <style>
          td, th {
              width: 3ex;
              text-align: right;
          }
      </style>

      <table>
          <tr>
              <th></th>
              <?php foreach (range(1$max_multiplier) as $x): ?>
                  <th><?= $x ?></th>
              <?php endforeach; ?>
          </tr>
          <?php foreach (range(1$max_multiplier) as $y): ?>
              <tr>
                  <th><?= $y ?></th>
                  <?php foreach (range(1$max_multiplier) as $x): ?>
                      <td><?= $x $y ?></td>
                  <?php endforeach; ?>
              </tr>
          <?php endforeach; ?>
      </table>
      Vielen Dank für deine Antwort.
      Das sieht nach einer High-end-Variante meiner Tabelle aus
      Das übersteigt bei weitem meine php-Skills...

      Kannst Du mir einen Tipp geben, wie ich aus meinem Script über eine kleine Anpassung die Tabelle im Anhang ausgeben lassen kann?
      Attached Files

      Comment


      • #4
        Originally posted by DrKalle View Post
        Das übersteigt bei weitem meine php-Skills...
        Dann solltest du dir die Zeit nehmen und versuchen das Script zu verstehen. Soviele PHP-Zeilen sind das ja nicht und wenn dir eine Funktion nicht bekannt ist, dann hilft die Doku.

        Comment


        • #5
          Originally posted by DrKalle View Post
          Kannst Du mir einen Tipp geben, wie ich aus meinem Script über eine kleine Anpassung die Tabelle im Anhang ausgeben lassen kann?
          Etwas denken und geht ganz simple.
          Obwohl die Lösung von @h3ll ja perfekt ist, kann ich dir auch nee Lösunf geben für deine Variante ,obwohl ich sie nicht gut finde.

          Link zur Lösung


          Code:
          <!DOCTYPE html> 
          <html lang="de"> 
          <head> 
          <meta charset="utf-8" /> 
          <title>E1_1mal1</title> 
          <style>
          td,th{
          width:20px;
          text-align:center;
          }
          </style>
          </head> 
              <body> 
              <h1>Das kleine 1 mal 1</h1> 
             <table> 
              <thead> 
              <?php 
                          echo "<th>*</th>"; 
                          for ($i = 1; $i <= 10; $i++) {  
                                      echo "<th>"; 
                                      echo $i; 
                                      echo "</th>";                                      } 
                          ?> 
                 </thead>  
                      <tbody> 
              <?php 
                        
          for ($i = 1; $i <= 10; $i++) { 
          echo "<tr><th>$i</th>"; 
          for ($j = 1; $j <= 10; $j++) { 
          echo "<td>";  
          echo ($i * $j); 
          echo "</td>"; 
          } 
          echo "</tr>"; 
          } 
                          ?> 
                          </tbody> 
                  </table> 
              </body> 
          </html>
          Last edited by basti1012; 24-08-2022, 22:13.

          Comment


          • #6
            Originally posted by basti1012 View Post
            Etwas denken und geht ganz simple.
            Obwohl die Lösung von @h3ll ja perfekt ist, kann ich dir auch nee Lösunf geben für deine Variante ,obwohl ich sie nicht gut finde.

            Code:
            <!DOCTYPE html> 
            <html lang="de"> 
            <head> 
            <meta charset="utf-8" /> 
            <title>E1_1mal1</title> 
            <style>
            td,th{
            width:20px;
            text-align:center;
            }
            </style>
            </head> 
                <body> 
                <h1>Das kleine 1 mal 1</h1> 
               <table> 
                <thead> 
                <?php 
                            echo "<th>*</th>"; 
                            for ($i = 1; $i <= 10; $i++) {  
                                        echo "<th>"; 
                                        echo $i; 
                                        echo "</th>";                                      } 
                            ?> 
                   </thead>  
                        <tbody> 
                <?php 
                          
            for ($i = 1; $i <= 10; $i++) { 
            echo "<tr><th>$i</th>"; 
            for ($j = 1; $j <= 10; $j++) { 
            echo "<td>";  
            echo ($i * $j); 
            echo "</td>"; 
            } 
            echo "</tr>"; 
            } 
                            ?> 
                            </tbody> 
                    </table> 
                </body> 
            </html>
            Hey basti, herzlichen Dank! Das ist für mich jedenfalls verständlich und hat mir sehr weitergeholfen.
            Habe mir eben die Lösung von h3ll nochmal in Ruhe angeschaut. Klar ist das perfekt, allerdings für mich mit wenigen Tagen Erfahrung mit php schwer reproduzierbar. Ich möchte erstmal ein grundsätzliches Verständnis entwickeln und das funktioniert für mich vorerst nur mit solchen unpraktischen aber für mich nachvollziehbaren Geschichten

            Schönen Sonntag euch allen

            Comment


            • #7
              Naja, Basti's Ansatz ist schon der bessere, weil es zur Lösung dieses Problems definitiv nicht notwendig ist drei Arrays mit Werten zu befüllen um diese dann auszugeben.
              carpe noctem

              [color=blue]Bitte keine Fragen per EMail ... im Forum haben alle was davon ... und ich beantworte EMail-Fragen von Foren-Mitgliedern in der Regel eh nicht![/color]
              [color=red]Hinweis: Ich bin weder Mitglied noch Angestellter von ebiz-consult! Alles was ich hier von mir gebe tue ich in eigener Verantwortung![/color]

              Comment

              Working...
              X