Tabelleninhalt sortieren und zählen

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

  • Tabelleninhalt sortieren und zählen

    Hallo PHP-Profies,

    ich habe mal ne Frage,
    wenn ich eine Tebellenspalte mit verschiedenen Inhalten habe,
    die sich aber wiederholen können und möchte dieses nun sortieren
    und angeben wie oft das selbe vorkam.

    Z.B.

    Eine Tabellespalte ( möbel ) mit folgenden Inhalt :

    möbel / stuhl
    möbel / tisch
    möbel / bank
    möbel / tisch
    möbel / ohne Inhalt
    möbel / lampe
    möbel / stuhl

    nun nehme ich folgenden Code um die Gegenstände zu sortieren :
    PHP Code:
     $sql "SELECT möbel from tabelle WHERE möbel != '' ''";
     
    $sql.= "GROUP BY möbel ";
     
    $res mysql_query($sql);
     
    $i 3;
     while (
    $row = @mysql_fetch_array($res)) {
       
    $möbel $row[0];
       
    $i++;
       echo 
    $möbel;
     } 
    und wie kann ich nun anzeigen, wie oft ein möbelstück vorkommt ?

    stuhl 2
    tisch 2
    bank 1
    lampe 1

    Danke im voraus

    Gruß Manuela

  • #2
    Sieh dir folgendes an:

    ORDER BY
    GROUP BY

    Comment


    • #3
      Sorry, habe nichts zu dieser Art der Sortierung gefunden,
      nur das womit ich Group selber einsetze.

      Gruß Manuela

      Comment


      • #4
        Schau Dir auch nochmal SELECT COUNT() an, dann sollte eigentlich alles klar sein.

        Comment


        • #5
          SELECT count(col_count), [single_cols] from tabelle WHERE bedingung GROUP BY single_cols
          Beantworte nie Threads mit mehr als 15 followups...
          Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

          Comment


          • #6
            Danke für die Antwort, aber irgendwie blicke ich nicht durch.

            Gruß Manuela

            Comment


            • #7
              PHP Code:
              $sql "SELECT COUNT(möbel) anzahl, möbel FROM tabelle GROUP BY möbel ";
               
              $res mysql_query($sql) or die(mysql_error());
               while (
              $row mysql_fetch_array($res)) {
                 echo 
              $row['anzahl'].'|',$row['möbel'].'<br>';
               } 
              Wobei ich nicht glaube, dass Deine tabellen spalte möbel heisst...
              Beantworte nie Threads mit mehr als 15 followups...
              Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25

              Comment


              • #8
                Ahhhhh - Danke !

                Kennst Du dich mit PHP v4.3.0 aus,
                denn dort habe ich richtig großes Problem
                und da Du ja gerade am Rechner sitzt vielleicht hast Du ja eine IDEE

                Post

                Gruß Manuela

                Comment

                Working...
                X