Left Join funktinoiert nicht!

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

  • Left Join funktinoiert nicht!

    Hallo @ all.

    Ich mache grad meine ersten gehversuche mit Joins und habe ein Problem.

    Ich habe folgende zwei Tabellen!

    Tabelle eintrag
    id int(14) auto_increment primary key,
    text text not null deafault ''

    Tabell comment
    id int(14) auto_increment primary key,
    textid int(14) not null default '0',
    comtext text not null default ''


    So ich will zu einem Eintrag Commentare abgeben und auf der Seite wo die Kommentare geschrieben werden sollen auch gleich nach dem posten die Kommentare ausgegeben werden und dazu soll auch der bestehende Eintrag mit ausgegeben werden. Also brauche ich Ausgaben aus zwei Tabellen und benötige Left Join.

    Hier mal die Abfrage!

    PHP-Code:
    <?php
    require('conf.php');

    if(isset(
    $_POST['comsend']))
    {
        
    $textid $_POST['id'];
        
    $text $_POST['comm'];
        
        
    $sqlbefehl ="Insert Into $tab_comment
                    (textid,comtext)
            VALUES    ('
    $textid','$text')
                    "
    ;
        
    $result mysql_query($sqlbefehl)or die(mysql_error());
        
    header("Location: eingabe3.php");
    }

    ?>
    <a href="eingabe1.php">Eingabe1</a> <a href="eingabe2.php">Eingabe2</a> <a href="ausgabe1.php">Ausgabe1</a>

    <table cellpadding="2" cellspacing="0" width="400" border="0">
    <tr>
    <td>Ausgabe1 Post</td>
    <tr>
    <?php
    $sqlbefehl 
    ="Select e.id,e.text From $tab_eintrag e.
                LEFT JOIN ON c.textid,c.comtext From 
    $tab_comment c.
                where textid="
    .$_GET['id']."";
    ?>
    <tr>
    <td>
    <?php
    //Ausgabe des Eintrages
    $ergebnis mysql_query($sqlbefehl)or die(mysql_error());
        
    $row mysql_fetch_assoc($ergebnis);
            
    $id $row['id'];
            
    $text $row['text'];
    echo 
    $text;
    ?>
    </td>
    </tr>
    </table>
    <br>
    <br>
    <table cellpadding="2" cellspacing="0" width="400" border="0">
    <tr>
    <td>Kommentare anzeigen!</td>
    </tr>
    <?php
    //Ausgabe aller Kommentare zum Eintrag
    $ergebnis mysql_query($sqlbefehl)or die(mysql_error());
        while(
    $row mysql_fetch_array($ergebnis)){
            
    $textid $row['textid'];
            
    $comtext $row['comtext'];
    echo
    "
    <tr>
    <td>
    "
    .$comtext."
    </td>
    </tr>
    "
    ;
    }
    ?>
    </table>
    <br>
    <br>
    <table cellpadding="2" cellspacing="0" width="400" border="0">
    <tr>
    <td colspan="2" align="center">Kommentar schreiben</td>
    <tr>
    <form action="<?php echo $_SERVER['PHP_SELF'?>" name="forcom" method="post">
    <input type="hidden" name="id" value="<?php echo $id?>">
    <tr>
    <td>kommentar:</td>
    <td><textarea name="comm" cols="40" rows="6"></textarea></td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" name="comsend" value="Speichern">
    </td>
    </tr>
    </form>
    </table>
    Und hier die Fehlermeldung die ich erhalte

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '. LEFT JOIN ON c.textid,c.comtext From comment c. where textid=1' at line 1


    Ich hoffe es kann mir jemand helfen. Vielen Dank MFG der Litter
    Zuletzt geändert von litterauspirna; 27.02.2008, 12:49.
    Aus dem Dynamo Lande kommen wir. Trinken immer reichlich kühles Bier. Und dann sind wir alle voll, die Stimmung ist so toll. Aus dem Dynamo Lande kommen wir.
    http://www.lit-web.de

  • #2
    Re: Left Join funktinoiert nicht!

    Original geschrieben von litterauspirna
    PHP-Code:
    <?php
    $sqlbefehl 
    ="Select e.id,e.text From $tab_eintrag e.
                LEFT JOIN ON c.textid,c.comtext From 
    $tab_comment c.
                where textid="
    .$_GET['id']."";
    ?>
    <tr>
    <td>
    <?php
    //Ausgabe des Eintrages
    $ergebnis mysql_query($sqlbefehl)or die(mysql_error());
        
    $row mysql_fetch_assoc($ergebnis);
            
    $id $row['id'];
            
    $text $row['text'];
    echo 
    $text;
    ?>
    du hast doch mysql_error() drine, schau dir die Meldung an. Und lese nochmals nach, wie ein JOIN syntaxtisch aufzubauen ist.

    P.S. Bitte das nächste Mal nur relevanten Code posten. Danke.

    Kommentar


    • #3
      Re: Re: Left Join funktinoiert nicht!

      Original geschrieben von asp2php
      Und lese nochmals nach, wie ein JOIN syntaxtisch aufzubauen ist.
      und wie Tabellen-Aliases angegeben werden.
      Die Fehlermeldung sagt dir aufs Zeichen genau, wo der (erste von vielen) Fehler ist.
      Gruss
      H2O

      Kommentar

      Lädt...
      X