Başka bir tablodaki bir tabloda kullanıcı adı Yorum aramak için sorgula

0 Cevap php

Ben aşağıdaki yapıda "giriş" adında bir MySQL tablo kullanıyorum:

loginid, username, password, email, actcode, disabled, activated, created, points

Ben aşağıdaki yapıda "yorum" adı verilen başka bir MySQL tablo kullanıyorum:

commentid, loginid, submissionid, comment, datecommented

Belirli bir "submisssionid" için, ben masa "açıklama" dan aşağıdaki bilgileri yazdırmak istiyorum:

-Alanlar "yorum" ve "datecommented".

Aynı zamanda, ben tablo "login" dan aşağıdaki yazdırmak istiyorum:

-Her satır tablodan seçilen satır olduğu için "LoginID" karşılık "username" "comment".

Bunu nasıl yapabilirim?

Ben aşağıdaki kodu denedim ama işe yaramadı.

Teşekkür peşin,

John

$submission = mysql_real_escape_string($_GET['submission']);
$submissionid = mysql_real_escape_string($_GET['submissionid']);


    $sqlStr = "SELECT 
                    c.loginid
                    ,c.submissionid
                    ,c.comment
                    ,c.datecommented
                    ,l.username
                    ,COUNT(c.commentid) countComments
                 FROM 
                    comment c
                WHERE
                    c.submissionid = $submissionid  
                INNER
                 JOIN
                    login l
                   ON
                    c.loginid = l.loginid
                 GROUP
                    BY
                     c.submissionid
                 ORDER  
                    BY 
                     c.datecommented DESC
                 LIMIT 
                     100";          

    $result = mysql_query($sqlStr);

    $arr = array(); 
    echo "<table class=\"samplesrec\">";
    while ($row = mysql_fetch_array($result)) { 
        echo '<tr>';
        echo '<td class="sitename1">'.$row["comment"].'</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td class="sitename2"><a href="http://www...com/sandbox/members/index.php?profile='.$row["username"].'">'.$row["username"].'</a>'.$row["datecommented"].'</td>';
        echo '</tr>';
        }
    echo "</table>";    

0 Cevap