Ankündigung

Einklappen
Keine Ankündigung bisher.

[Erledigt] order by funktioniert nicht

Einklappen

Neue Werbung 2019

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

  • [Erledigt] order by funktioniert nicht

    Hallo,
    habe eine Abfrage aus 2 Tabellen erswtellt. Funktioniert, jedoch nur ohne Sortierung mit order by.
    Hier der Quelltext mit order by. Kann mir da jemand helfen? Danke.

    html>
    <head>
    <title>xxx</title>
    </head>

    <body>
    <h2>*** Tabellenbeschriftung ***</h2>
    <?php

    require_once "../id_db.php";

    $abfrage = "SELECT T1.VERBINDUNG, T2.Nachname, T2.Vorname, T2.Status FROM T1, T2
    order by T2.Vorname asc
    where T1.ID = T2.ID and (T1.VERB_TYP = 4 or T1.VERB_TYP = 1001)
    and (T2.status=1 or T2.status=2 or T2.status=3 or T2.status=5 or T2.status=6)"
    ;

    $ergebnis = mysql_query($abfrage)
    OR die("Error: $abfrage <br>".mysql_error());

    echo "<table width=\"400px\" border=\"2\">";
    echo "<tr>";

    echo "<td width=\"200px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Nachname</b></span></td>";
    echo "<td width=\"150px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Vorname</b></span></td>";
    echo "<td width=\"50px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Status</b></span></td>";
    echo "</tr>";

    while($row = mysql_fetch_object($ergebnis))

    {

    $nname = "$row->Nachname, $row->Vorname";
    $vname = $row->Vorname;
    $VERBINDUNG = $row->VERBINDUNG;

    echo "<tr>";
    echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $nname . "</span></td>";
    echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $vname . "</span></td>";
    echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $VERBINDUNG . "</span></td>";
    echo "</tr>";

    }

    echo "</table>";


    mysql_close();
    ?>
    </body>
    </html>

  • #2
    http://php-de.github.io/jumpto/sql/

    deine sql-syntax ist falsch. order by darf nicht vor der where klausel stehen.

    die mysql_* funktionen sind veraltet. nutze mysqli oder pdo.

    dein query ließe sich außerdem noch etwas übersichtlicher schreiben (ungetestet):

    Code:
    select T1.VERBINDUNG, T2.Nachname, T2.Vorname, T2.Status 
    from T1 join T2 using (ID)
    where 
        T1.VERB_TYP in (4,1001)
        and T2.status between 1 and 6
    order by T2.Vorname asc
    JOIN nutzen, wenn join gewünscht
    IN clause wenn eine spalte mehrere werte haben darf
    oder BETWEEN wenn die werte in einem bestimmten bereich sein dürfen

    ließt sich leichter als where .... or ... or .... or .... or .... or .... or ..... or .... or ... usw
    liebe Grüße
    Fräulein Dingsda

    Kommentar


    • #3
      Danke, habe jetzt den Code dementsprechend geändert, jedoch gleiches Problem. Ohne order by bestens, mit order by Fehlermeldung "Parse error: syntax error, unexpected T_STRING in ( Zeile mit order by)"

      Kommentar


      • #4
        Zitat von wepsi Beitrag anzeigen
        jedoch gleiches Problem
        ein parse error ist doch nicht das gleiche wie eine falsche ausgabe.
        daher hast du jetzt nicht das gleiche problem.

        jetzt hast du nur das problem, dass du irgendwas in php falsch gemacht hast.
        wahrscheinlich beendest du den string schon vor dem "order by..."
        http://www.schattenbaum.net/php/unexpected_T_STRING.php

        ohne code können wir aber nur hellsehen
        liebe Grüße
        Fräulein Dingsda

        Kommentar


        • #5
          Hallo,
          Ihr merkt es schon, Anfänger.
          Aber nochmal etwas genauer. Sobald ich den Quellcode ohne order by ausführe, bekomme ich meine Tabelle dargestellt, leider halt nicht sortiert. Sobald ich order by mit hinzufüge, kommt keine Ausgabe mehr, sondern nur noch der Parse Error. Ich verändere sonst nichts ausser die Zeile order by.Übrigens, die Funktion between kann ich nicht nehmen, da einzelne Stati nicht ausgewertet sollen.
          Anbei nochmal mein kompletter Quelltext:

          <html>
          <head>
          <title>xxx</title>
          </head>

          <body>
          <h2>*** Tabellenbeschriftung ***</h2>
          <?php

          require_once "../id_db.php";

          $abfrage = "SELECT T1.VERBINDUNG, T2.Nachname, T2.Vorname, T2.Status
          From T1 join T2 using (ID)
          where T1.VERB_TYP in (4, 1001)
          and (T2.status=1 or T2.status=2 or T2.status=3 or T2.status=5 or T2.status=6)"
          order by T2.Vorname asc;

          $ergebnis = mysql_query($abfrage)
          OR die("Error: $abfrage <br>".mysql_error());

          echo "<table width=\"400px\" border=\"2\">";
          echo "<tr>";

          echo "<td width=\"200px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Nachname</b></span></td>";
          echo "<td width=\"150px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Vorname</b></span></td>";
          echo "<td width=\"50px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Status</b></span></td>";
          echo "</tr>";

          while($row = mysql_fetch_object($ergebnis))

          {

          $nname = "$row->Nachname, $row->Vorname";
          $vname = $row->Vorname;
          $VERBINDUNG = $row->VERBINDUNG;

          echo "<tr>";
          echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $nname . "</span></td>";
          echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $vname . "</span></td>";
          echo "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" . $VERBINDUNG . "</span></td>";
          echo "</tr>";

          }

          echo "</table>";


          mysql_close();
          ?>
          </body>
          </html>

          Kommentar


          • #6
            es gibt code tags, um geposteteten code aufzuhübschen.

            Kommentar


            • #7
              Wie gesagt Anfänger, sorry.
              PHP-Code:
              <html>
              <head>
              <title>xxx</title>
              </head>

              <body>
              <h2>*** Tabellenbeschriftung ***</h2>
              <?php

              require_once "../id_db.php";

              $abfrage "SELECT T1.VERBINDUNG, T2.Nachname, T2.Vorname, T2.Status
              From T1 join T2 using (ID)
              where T1.VERB_TYP in (4, 1001)
              and (T2.status=1 or T2.status=2 or T2.status=3 or T2.status=5 or T2.status=6)"
              order by T2.Vorname asc;

              $ergebnis mysql_query($abfrage)
              OR die(
              "Error: $abfrage <br>".mysql_error());

              echo 
              "<table width=\"400px\" border=\"2\">";
              echo 
              "<tr>";

              echo 
              "<td width=\"200px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Nachname</b></span></td>";
              echo 
              "<td width=\"150px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Vorname</b></span></td>";
              echo 
              "<td width=\"50px\"><span style='font-family:Arial, Verdana; font-size:15px; color:#0000FF;'><b>Status</b></span></td>";
              echo 
              "</tr>";

              while(
              $row mysql_fetch_object($ergebnis))

              {

              $nname "$row->Nachname$row->Vorname";
              $vname $row->Vorname;
              $VERBINDUNG $row->VERBINDUNG;

              echo 
              "<tr>";
              echo 
              "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" $nname "</span></td>";
              echo 
              "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" $vname "</span></td>";
              echo 
              "<td><span style='font-family:Arial, Verdana; font-size:10px; color:#0000FF;'>" $VERBINDUNG "</span></td>";
              echo 
              "</tr>";

              }

              echo 
              "</table>";


              mysql_close();
              ?>
              </body>
              </html>

              Kommentar


              • #8
                Hallo, danke für die Hilfe, habe den fehler gefunden; die " waren falsch gesetzt.

                Kommentar

                Lädt...
                X