Sorgu Çalışmıyor Katıl

1 Cevap php

Ben üç MySQL tablo kullanıyorum:

yorum

yorumid loginid boyun eğmeid yorum dateyorumed

giriş

loginid username password email actcode disabled activated created points

boyun eğme

boyun eğmeid loginid title url displayurl datesubmitted

Bu üç tablolarda, "LoginID" karşılık gelmektedir.

I would like to pull the top 10 loginids based on the number of "boyun eğmeid"s. I would like to display them in a 3-column HTML table that shows the "username" in the first column, the number of "boyun eğmeid"s in the second column, and the number of "yorumid"s in the third column.

Ben aşağıda sorgusunu kullanarak denedim ama işe yaramadı. Herhangi bir fikir neden olmasın?

Teşekkür peşin,

John

$sqlStr = "SELECT
                 l.username 
                 ,l.loginid  
                 ,c.yorumid 
                 ,count(s.yorumid) countComments
                 ,c.yorum 
                 ,c.dateyorumed 
                 ,s.boyun eğmeid 
                 ,count(s.boyun eğmeid) countSubmissions
                 ,s.title
                 ,s.url 
                 ,s.displayurl 
                 ,s.datesubmitted
            FROM yorum AS c
      INNER JOIN girişAS l ON c.loginid = l.loginid
      INNER JOIN boyun eğme AS s ON c.loginid = s.loginid
        GROUP BY c.loginid
        ORDER BY countSubmissions DESC
           LIMIT 10";

  $result = mysql_query($sqlStr);

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

1 Cevap

In your query , you have selected non-group items such as commentid , comment etc. This should give the desired result.

select l.username , count(s.submissionid) as NoOfSubmissions,count(c.commentid) as NoOfComments from comment c INNER JOIN submission s ON c.submissionid = s.submissionid INNER JOIN login l ON l.loginid = c.loginid group by l.username order by count(s.submissionid) limit 10;

Teşekkürler,

Rinson KE DBA 91 + 9995044142 www.qburst.com