Problem mit der Ausgabe

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Problem mit der Ausgabe

    Wer kann mir helfen meinen Denkfehler auszuzeign.

    PHP-Code:
    <?php
    $txt 
    = array(array('Produkt'=>'S','Nummer'=>'50','Leistung'=>'400','Preis'=>'0.99'),
                 array(
    'Produkt'=>'M','Nummer'=>'51','Leistung'=>'500','Preis'=>'1.99'),
                 array(
    'Produkt'=>'L','Nummer'=>'52','Leistung'=>'600','Preis'=>'10.99'));

    echo 
    '<table border="1">';
    for (
    $i 0$i count($txt);$i++)
    {
        for(
    $j 0$j count($txt[$i]); $j++)
        {
            if(
    $i == 0)
            {
                echo 
    '<tr>';
                echo 
    '  <td>Produkt</td>';
            }
            echo 
    '<td>'.$txt[$i]['Produkt'].'&nbsp;</td>';
            if(
    $i == count($txt))
            {
                echo 
    '</tr>';
            }
        }
    }
    echo 
    '</table>';
    ?>
    Eigentlich möchte ich folgende Ausgabe bekommen
    Zeile 1 Spalte 1 => Name (Produkt)
    Zeile 1 Spalte 2 => 1. Produktname
    usw.
    Zeile 2 Spalte 1 => Artikelnummer (Nummer)
    Zeile 2 Spalte 2 => 1.Produkt Artikelnr.
    usw.

    Aber ich habe da scheinbar noch einen groben denkfehler drin.
    Zuletzt geändert von Wotan; 27.04.2004, 14:31.
    *winks*
    Gilbert
    ------------------------------------------------
    Hilfe für eine Vielzahl von Problemen!!!
    http://www.1st-rootserver.de/

  • #2
    for($j = 0; $j < count($txt[$i]); $j++)
    das bringt doch bei einem asso-array nichts....

    mache ein print_r() auf das array. dann siehst du was du brauchst...

    ach ja ... und zahlen gehören nicht in '-zeichen.
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      Witzbold.

      Das mit dem print_r habe ich gemacht. Darum geht es ja auch garnicht. Ich bekomm die Ausgabe nicht hin.
      *winks*
      Gilbert
      ------------------------------------------------
      Hilfe für eine Vielzahl von Problemen!!!
      http://www.1st-rootserver.de/

      Kommentar


      • #4
        ich bin grad nicht in der lage, mir die tabelle vorzustellen, wie wär's mit nem beispiel?
        am besten die tabelle, so wie sie mit deinem array $txt aussehen soll
        Ich denke, also bin ich. - Einige sind trotzdem...

        Kommentar


        • #5
          so soll die Ausgabe nachher aussehen:
          PHP-Code:
          <table>
          <
          tr>
              <
          td>Produkt-Name</td>
              <
          td>$array['0']['Produkt']</td>
              <
          td>$array['1']['Produkt']</td>
              <
          td>$array['2']['Produkt']</td>
              <
          td>$array['3']['Produkt']</td>
          </
          tr>
          <
          tr>
              <
          td>Artikel-Nummer</td>
              <
          td>$array['0']['Nummer']</td>
              <
          td>$array['1']['Nummer']</td>
              <
          td>$array['2']['Nummer']</td>
              <
          td>$array['3']['Nummer']</td>
          </
          tr>
          <
          tr>
              <
          td>Leistung</td>
              <
          td>$array['0']['Leistung']</td>
              <
          td>$array['1']['Leistung']</td>
              <
          td>$array['2']['Leistung']</td>
              <
          td>$array['3']['Leistung']</td>
          </
          tr
          usw.
          *winks*
          Gilbert
          ------------------------------------------------
          Hilfe für eine Vielzahl von Problemen!!!
          http://www.1st-rootserver.de/

          Kommentar


          • #6
            hast du nur eine begrenzte anzahl an Produkten(3-4)? sonst wird die tab recht breit und unleserlich.

            oder du müsstest noch einen Counter mitlaufen lassen der nach x Produkten eine neue tab anlegt.
            mfg
            marc75

            <Platz für anderes>

            Kommentar


            • #7
              Nein es sind eine begrenzte Anzahl an Produkten die zur Ansicht kommen. Sind immer nur 5 Stück die über eine Datenbank gefüllt werden.
              *winks*
              Gilbert
              ------------------------------------------------
              Hilfe für eine Vielzahl von Problemen!!!
              http://www.1st-rootserver.de/

              Kommentar


              • #8
                PHP-Code:
                $felder array_keys(current($txt));
                echo 
                '<table>';
                foreach(
                $felder as $feld)
                {
                  echo 
                '<tr><td>'.$feld.'</td>';
                  foreach(
                $txt as $eintrag)
                    echo 
                '<td>'.$eintrag[$feld].'</td>';
                  echo 
                '</tr>';
                }
                echo 
                '</table>'
                Ich denke, also bin ich. - Einige sind trotzdem...

                Kommentar


                • #9
                  so? (nur hingemüllt )
                  PHP-Code:
                  <?php

                      $txt 
                  = array( array('Produkt' => 'S''Nummer' => 50'Leistung' => 400'Preis'=>  0.99),
                                    array(
                  'Produkt' => 'M''Nummer' => 51'Leistung' => 500'Preis'=>  1.99),
                                    array(
                  'Produkt' => 'L''Nummer' => 52'Leistung' => 600'Preis'=> 10.99) );


                      if (
                  count($txt)>0)
                      {

                          echo 
                  '<table border="1">';

                          echo 
                  '<tr>';
                              foreach (
                  $txt[0] as $key => $value)
                                  echo 
                  '<td>'.$key.'</td>';
                          echo 
                  '<tr>';

                          for (
                  $i=0$i<count($txt);++$i)
                          {
                              echo 
                  '<tr>';
                                  foreach (
                  $txt[$i] as $key => $value)
                                      echo 
                  is_numeric($value) ? '<td>'.number_format($value,2,',','.').'</td>' '<td>'.$value.'</td>';;
                              echo 
                  '<tr>';
                          }

                          echo 
                  '</table>';
                      }

                      echo 
                  '<hr>';
                      echo 
                  show_source(__FILE__);

                  ?>
                  INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                  Kommentar


                  • #10
                    Original geschrieben von Abraxax
                    so?
                    schätzungsweise nein, da der liebe wotan die einträge ja nicht unter- sondern nebeneinander haben möchte
                    Ich denke, also bin ich. - Einige sind trotzdem...

                    Kommentar


                    • #11
                      kann ja sein. aber ich habe es versucht ...
                      INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                      Kommentar


                      • #12
                        du warst stets bemüht und kannst dir dein arbeitszeugnis briefumschlagkonform gefaltet abholen
                        Ich denke, also bin ich. - Einige sind trotzdem...

                        Kommentar


                        • #13
                          Original geschrieben von mrhappiness
                          schätzungsweise nein, da der liebe wotan die einträge ja nicht unter- sondern nebeneinander haben möchte
                          thx Happy. Manchmal steht man wie die Kuh vor offenen Tor.
                          Zuletzt geändert von Wotan; 27.04.2004, 15:04.
                          *winks*
                          Gilbert
                          ------------------------------------------------
                          Hilfe für eine Vielzahl von Problemen!!!
                          http://www.1st-rootserver.de/

                          Kommentar


                          • #14
                            @happy
                            so gehört sich das ....
                            INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                            Kommentar


                            • #15
                              Original geschrieben von Wotan
                              Manchmal steht man wie die Kuh vor offenen Tor.
                              das wird haxe gar nicht gern hören
                              Ich denke, also bin ich. - Einige sind trotzdem...

                              Kommentar

                              Lädt...
                              X