MySQL Abfrage

Dieses Thema im Forum "Webentwicklung" wurde erstellt von Hennington, 23. April 2006 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 23. April 2006
    Moin!
    Hab ne Communityseite, bei der man Photos von Partys usw. in Alben hochladen kann und Alben erstellen kann usw. sprich eine Bildergallerie.
    So, jetzt möchte ich gerne eine detaillierte Statistik haben, da die leider nicht integriert ist und es auch kein Addon gibt, mache ichs selbst (Auch ohne jegliche Ahnung von PHP)..
    Hab mir jetzt mal überlegt, wie das ganze rein theoretisch funktionieren müsste.
    Ich habe eine MySQL Datenbank mit dem namen "eutin".
    Darin befinden sich viele Tabellen, beispielsweise auch die Tabelle "g2_Users". In der Tabelle gibts dann mehrere Spalten, in welchen die Daten alle eingetragen sind usw.
    Ich möchte jetzt via PHP irgendwie zählen lassen, wieviele Einträge diese Tabelle hat, um herauszufinden, wieviele User registriert sind.
    Das Ergebnis soll dann via echo Befehl ausgegeben werden.
    Unter diesem Prinzip möchte ich jetzt also folgende Informationen aus den verschiedenen Tabellen in der DB suchen:
    Fotos gesamt
    Hauptalben gesamt
    Sub-Alben gesamt
    Kommentare gesamt
    Bewertungen gesamt
    Angemeldete User gesamt
    User online
    Visits des letzten Tages
    Visits der letzten Woche
    Visits des letzten monats
    Visits des letzten Jahres
    Visits gesamt

    Was mir jetzt also zu meinem glück fehlt ist der Befehl für die Abfrage und der Befehl für die Ausgabe.
    Sprich: Es muss auf die MySQL DB connectet werden, die Einträge der Tabelle "g2_Users" gezählt werden, das Ergebnis zu einer Variable bestimmt werden und der Echo Befehl für die entstandene Variable muss eingesetzt werden. Das ganze vervielfältige ich dann nachher einfach und passe das auf die DB, den User und die Tabellen an und packs in ne Tabelle damits gut aussieht.


    Danke schonmal für jede Hilfe! 10er ist auf jeden Fall drin!
     
  2. 24. April 2006
    Code:
    //datenbankverbindung
    $server = "localhost";
    $user = "USERl";
    $pass = "PASS";
    $datenbank = "DB_NAME"; //in deinem Fall also "eutin"
    
    $verbindung = mysql_connect($server,$user,$pass) or die ("Keine Verbindung zur Datenbank möglich");
    mysql_select_db($datenbank);
    
    
    //mit dieser variante hier liest du alles gleichzeitig aus und hast dann jeweils in der variable //$count_TABELLENNAME die anzahl der einträge gespeichert.
    
    
    $query = 'mysql_list_tables("eutin")';
    while($row = mysql_fetch_row($query)) {
     $sql = 'SELECT COUNT(*) FROM "$row[0]"';
     ${$count_ . $row[0]} = mysql_query($sql);
    }
    
    echo $count_g2_users;
    echo $UND_SO_WEITER;
    echo $UND_SO_WEITER;
    
    /*------------------------------------------------------------------------------------------------------*/
    
    //variante 2...ich empfehl allerdings eins, weil bei dieser art wird der code sehr viel größer...
    
    //einträge in der jeweiligen db zählen
    $sql = 'SELECT COUNT(*) FROM "g2_Users"'; //natürlich hier dann den jeweiligen tabellen-namen angeben
    $count = mysql_query($sql);
    
    //ausgabe der anzahl der einträge
    echo $count;
    
    
    hoffe, das ist das, was du meintest...wenn nicht einfach nochma fragen ^^

    mfg
    fake
     
  3. 24. April 2006
    Hab mich für die erste Methode entschieden und mein Code sieht ejtzt folgendermaßen aus:

    Code:
    <?
    $server = "localhost";
    $user = "eutin";
    $pass = "****";
    $datenbank = "gallery";
    
    $verbindung = mysql_connect($server,$user,$pass) or die ("Keine Verbindung zur Datenbank möglich");
    mysql_select_db($datenbank);
    
    $query = mysql_list_tables("gallery");
    while($row = mysql_fetch_row($query)) {
     $sql = 'SELECT COUNT(*) FROM "$row[0]"';
     ${$count_ . $row[0]} = mysql_query($sql);
    }
    
    echo "Statistik:";
    echo "<BR>";
    echo "Angemeldete User: $count_g2_User";
    echo "<BR>";
    echo "Benutzergruppen: $count_g2_Group";
    echo "<BR>";
    echo "Photos gesamt: $count_g2_PhotoItem";
    echo "<BR>";
    echo "Alben gesamt: $count_g2_AlbumItem";
    
    ?>
    Ausgegeben bekomme ich auf der Site jetzt dies hier:
    Statistik:
    Angemeldete User:
    Benutzergruppen:
    Photos gesamt:
    Alben gesamt:

    Fehlen irgendwie noch die Wertte. Hat da jemand ne Ahnung, woran das liegt??
     
  4. 25. April 2006
    hier die funktionierende lösung: (hatten sich in der schnelle paar fehler eingeschlichen ^^)

    Code:
    <?
    //datenbankverbindung
    
    $server = "localhost";
    $user = "eutin";
    $pass = "****";
    $datenbank = "gallery"; 
    
    $verbindung = mysql_connect($server,$user,$pass) or die ("Keine Verbindung zur Datenbank möglich");
    mysql_select_db($datenbank);
    
    $result = mysql_list_tables($datenbank);
    
    while($row = mysql_fetch_row($result)) {
     
     $sql = "SELECT COUNT(*) FROM" . " $row[0]";
     $query = mysql_query($sql);
     
     while($table = mysql_fetch_array($query)) {
     
     ${$count_ . $row[0]} = $table[0];
     
     }
    }
    
    echo $count_g2_User;
    echo $UND_SO_WEITER;
    echo $UND_SO_WEITER;
    
    ?>
    
    mfg
    fake
     
  5. 25. April 2006
    Geht irgendwie auch nicht :/
    Mein Quellcode sieht jetzt also folgendermaßen aus:
    Code:
    <?
    //datenbankverbindung
    
    $server = "localhost";
    $user = "eutin";
    $pass = "****";
    $datenbank = "gallery"; 
    
    $verbindung = mysql_connect($server,$user,$pass) or die ("Keine Verbindung zur Datenbank möglich");
    mysql_select_db($datenbank);
    
    $result = mysql_list_tables($datenbank);
    
    while($row = mysql_fetch_row($result)) {
     
     $sql = "SELECT COUNT(*) FROM" . " $row[0]";
     $query = mysql_query($sql);
     
     while($table = mysql_fetch_array($query)) {
     
     ${$count_ . $row[0]} = $table[0];
     
     }
    }
    
    echo "Statistik:";
    echo "<BR>";
    echo "Angemeldete User: $count_g2_User";
    echo "<BR>";
    echo "Benutzergruppen: $count_g2_Group";
    echo "<BR>";
    echo "Photos gesamt: $count_g2_PhotoItem";
    echo "<BR>";
    echo "Alben gesamt: $count_g2_AlbumItem";
    ?>
    
    Muss ich irgendwo noch etwas eintragen oder so, oder in der SQL Tabelle irgendwelche Rechte geben, damit man das auslesen kann???
    Nur mal so, falls dir das weiterhilft, die URL zur Seite ist http://eutin.basepage.de und der Direktlink zu der Statistik PHP-Datei ist folgender:
    http://eutin.basepage.de/gallery2/statistic2.php

    Da kannst dir das dann ja vlt. mal angucken. Muss ich die Dateien vielleicht auch. php3 oder .php4 nennen oder sowas??


    PS:
    Code:
     
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    
    Notice: Undefined variable: count_ in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 22
    Statistik:
    
    Notice: Undefined variable: count_g2_User in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 29
    Angemeldete User:
    
    Notice: Undefined variable: count_g2_Group in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 31
    Benutzergruppen:
    
    Notice: Undefined variable: count_g2_PhotoItem in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 33
    Photos gesamt:
    
    Notice: Undefined variable: count_g2_AlbumItem in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 35
    Alben gesamt:
    Notice: Undefined variable: count_g2_User in /var/www/vhosts/eutin.basepage.de/httpdocs/gallery2/statistic2.php on line 36
    
    Das is die Fehlermeldung, die ich bekomme, nachdem ich da nen befehl zum Anzeigen aller Fehler eingefügt habe.
     
  6. 25. April 2006
    was für eine php version hast du denn?

    mfg
    fake
     
  7. 25. April 2006
    Müsste ne aktuelle sein....
    Naja, werd da morgen mal den Anbieter fragen welche Version das ist.. kannst ja nochmal genau gucken ob du Fehler drin findestz oder vlt. auch jemand anders.
     
  8. 25. April 2006
    Auf den ersten Blick (ohne zu testen) würde ich sagen, probiere mal das hier:

    ${'count_'.$row[0]} = $table[0];

    count_ ist doch eine Zeichenkette, keine Variable...

    Grüße, Scaron
     
  9. 26. April 2006
    Funktioniert einwandfrei! ich liebe dich
    vielen Dank dafür an euch beide.
     
  10. 26. April 2006
    ja stimmt =) komischwerweise hatter bei mir das $count genommen...naja, liegt wohl an unterschiedlichen versionen...

    mfg
    fake
     
  11. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.