GROUP BY mit einem Spaltenwert nur eindeutige Inhalte ausgeben

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

  • GROUP BY mit einem Spaltenwert nur eindeutige Inhalte ausgeben

    Hallo,
    ich habe hier eine Reihe mit sagen wir dem Inhalt eins für die Spalte raum. Dieser Inhalt ist in der Datenbank zwei mal vorhanden. Nun möchte ich, dass die Reihe nur einmal ausgegeben wird. Versucht habe ich es so:

    PHP Code:
      public static function refreshRooms($id$consultant)
        {
          
    $arr = array();
          
    $jsonData '{"results":[';
          
    $db_connection = new mysqliself::DB_HOSTself::DB_USERself::DB_PASSWORDself::DB_NAME);
          
    $db_connection->query"SET NAMES 'UTF8'" );
          
    $statement $db_connection->prepare"SELECT DISTINCT id, author, room FROM wov_webchat_lines WHERE id > ? AND ts >= DATE_SUB(NOW(), INTERVAL 10 HOUR) AND author != '$consultant' GROUP BY room");
          
    $statement->bind_param'i'$id);
          
    $statement->execute();
          
    $statement->bind_result($id$author$room);
          
    $line = new stdClass;
          while (
    $statement->fetch()) {
            
    $line->id $id;
            
    $line->room $room;
            
    $line->author $author;
            
    $line->main_id 158;
            
    $line->forms_token $_SESSION['forms_token'];
            
    $arr[] = json_encode($line);
          }
          
    $statement->close();
          
    $db_connection->close();
          
    $jsonData .= implode(","$arr);
          
    $jsonData .= ']}';
          return 
    $jsonData;
        } 
    Hat mir jemand ein Tipp, wie man das am besten hinkriegt?

  • #2
    Welcher Inhalt ist doppelt? author oder room?

    Gruß
    Peter
    Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
    Meine Seite

    Comment


    • #3
      room ist doppelt und author ist doppelt

      room ist doppelt und author ist doppelt

      Comment


      • #4
        So gehts

        PHP Code:
        public static function refreshRooms($id$consultant)
            {
              
        $arr = array();
              
        $jsonData '{"results":[';
              
        $db_connection = new mysqliself::DB_HOSTself::DB_USERself::DB_PASSWORDself::DB_NAME);
              
        $db_connection->query"SET NAMES 'UTF8'" );
              
        $statement $db_connection->prepare"SELECT DISTINCT id, author, room FROM wov_webchat_lines WHERE id > ? AND ts >= DATE_SUB(NOW(), INTERVAL 100 HOUR) AND author != '".$consultant."' GROUP BY  room, author");
              
        $statement->bind_param'i'$id);
              
        $statement->execute();
              
        $statement->bind_result($id$author$room);
              
        $line = new stdClass;
              while (
        $statement->fetch()) {
                
        $line->id $id;
                
        $line->room $room;
                
        $line->author $author;
                
        $line->main_id 158;
                
        $line->forms_token $_SESSION['forms_token'];
                
        $arr[] = json_encode($line);
              }
              
        $statement->close();
              
        $db_connection->close();
              
        $jsonData .= implode(","$arr);
              
        $jsonData .= ']}';
              return 
        $jsonData;
            } 

        Comment

        Working...
        X